MQTT Subscribe

This function block is designed to subscribe to a specified MQTT topic and receive messages. It allows you to integrate MQTT communication within your application seamlessly.

πŸ“₯ Inputs

Enable This boolean input enables or disables the MQTT subscription.

πŸ“€ Outputs

Data This output provides the latest message received on the subscribed MQTT topic.

New Data A boolean output that indicates whether new data has been received since the last evaluation.

πŸ•ΉοΈ Controls

MQTT Topic Input A field where the user can specify the topic to which this block wants to subscribe.

Reconnect A toggle or button that allows the user to reconnect to the MQTT broker with updated settings.

🎨 Features

Real-Time Messaging The block continuously listens for messages on the specified MQTT topic and updates outputs in real time.

Dynamic Subscription Management The block can handle changes in subscription parameters, allowing for dynamic adjustments without reconnecting.

Connection Status Logging Information about connection status and received messages is logged, aiding in debugging and monitoring.

πŸ“ Usage Instructions

  1. Enter MQTT Topic: Specify the MQTT topic in the MQTT Topic Input field.

  2. Enable Subscription: Connect a boolean signal to the Enable input to allow or disallow subscription.

  3. Receive Messages: The latest messages will be provided through the Data output, and the New Data output will indicate if new messages have been received since the last evaluation.

  4. Cleanup: When finished, the block will automatically disconnect from the MQTT broker when removed or deactivated.

πŸ“Š Evaluation

On each evaluation cycle, this function block checks if data has been received, returning the newest message along with a flag indicating whether it is new.

πŸ’‘ Tips and Tricks

Testing Connectivity

Ensure that your MQTT broker is accessible from your network before subscribing. If you experience issues, check your broker settings.

Receiving JSON data

If you are receiving JSON formatted messages, consider using a Data Type Converter block afterward to process the incoming string into usable data structures.

Debugging messages

Utilize logging outputs to monitor data received and connection status. This can help troubleshoot connectivity or subscription issues.

πŸ› οΈ Troubleshooting

Connection Failure

If you receive a connection failure, verify the broker URI, credentials, and that the broker is running. Check your internet connection and firewall settings as well.

No New Data Received

Make sure that there are publications on the topic you are subscribed to. Check other devices or applications to ensure they are emitting messages.

Last updated