Example: Connecting to MQTT broker from HiveMQ
Modbus is a data communications protocol and has become a de facto standard protocol to connect industrial electronic devices. But how could those devices become part of the internet of things and what use cases could be developed? With this series of blog articles, we would like to give answers, ideas, suggestions, and helpful hints. To demonstrate how easy, it is to bridge the gap between devices and IT/cloud infrastructure by using Modbus Cloud Connect.
In this example, 4 components are used: A temperature sensor, a gateway with middleware and a MQTT-Broker.
What exactly is an MQTT-Broker and what is MQTT?
MQTT is a client-server publish or subscribe-messaging transport protocol. It is open, simple, and designed to be easy to implement. The client (publisher), in this case the middleware, sends messages to the broker with a topic. The IoT platform (subscriber) receives the message on this subscribed topic. The MQTT-Broker acts as an intermediary between the publisher and subscriber, receiving the messages and forwarding them to the subscriber based on the topic.
Modbus RTU communication protocol
The readings from the temperature sensor are read by the gateway, in this example Modbus Cloud Connect, using Modbus RTU protocol. Modbus RTU (Remote Terminal Unit) is based on the master-slave system. Each bus participant has been assigned a unique address via which it can be addressed directly. The Modbus master (gateway) sends a message to the slave (temperature sensor) and receives a corresponding response.
Narrowband-IoT
The Modbus Cloud Connect gateway contains a mobile radio modem with a SIM chip. This establishes a connection to the mobile network and sends the measured values to the middleware via Narrowband-IoT (NB-IoT) . NB-IoT comes from the family of Low Power Wide Area Networks (LPWAN). Installations such as in the basement do not pose a problem due to the high building penetration. This makes Narrowband-IoT the ideal transmission standard for use cases inside objects.
MQTT broker
The measured values are now in the “cloud” and are sent from there via MQTT protocol to an MQTT broker. No measured values are stored in the middleware or the self-service portal of Modbus Cloud Connect, but only forwarded to the desired IoT platform.
An MQTT broker can be operated completely independently or a SaaS (Software as a Service) solution can be used. The company HiveMQ, for example, offers a limited free version. Up to 100 devices can be created. The data volume is 10 GB. This is particularly suitable for familiarizing yourself with MQTT or for uncomplicated tests. To do this, you sign up and create a cluster. This provides the access data for the connection to the broker.
To send messages from the gateway to the MQTT-Broker, you need the host (URL), port, credentials for authentication and the topic described above. Either the topic is provided by the gateway or you choose your own topic structure.
Now messages can be sent to the broker. The platform of HiveMQ offers a WebClient to view the received messages. With the multi-level wildcard # as placeholder without further input all messages are received that are sent to the broker (subscription).
Using the same principle, the desired software (IoT platform) can now subscribe to messages in order to visualize or evaluate them.
Modbus Cloud Connect makes it easy to use, flexibly connectable and broadly applicable. Your device, directly to the cloud.