Wireless M-Bus to NB-IoT - MQTT
Integration manual for the ACRIOS Systems converters ACR-CV-101NI-W-D2 and ACR-CV-101NI-W433-D2 for Wireless M-Bus smart meters readout and data transmission to the MQTT broker via NB-IoT network.
MQTT is supported on firmware version 2.14.2 and higher.
Introduction
MQTT (Message Queuing Telemetry Transport) is a lightweight messaging protocol for small sensors and mobile devices optimized for high-latency or unreliable networks. MQTT is a publish/subscribe messaging protocol that works on top of the TCP/IP protocol.
This article covers the following topics:
- Script principle
- MQTT protocol
- MQTT broker setup
- Lua script - the configuration
- Configuration messages
This manual describes a use of the MQTT Lua script with HiveMQ brokers.
Script Principle
Communication diagram
Key Functionalities
- The converter listens to the meter transmissions during a configured time period and creates a table of known meters to prevent multiple instances of sending the same meter payload.
- The converter captures the payloads and publishes them to the MQTT broker.
- The converter plans automatic readouts based on the configuration.
- The converter starts gathering data at a specified time, which can be delayed based on a time spread parameter. This function allows the reduction of peak load on the broker by time spreading the publication of the data.
- Additionally, the converter periodically publishes a "beacon" message, which is a short message that indicates the device is operational and connected to the network. After publishing the beacon message, the device checks for any configuration changes or actions to execute.
The converter can listen to and read data from meters operating in wireless T and C modes simultaneously.
Boot-up and scheduled actions diagram
The system starts by booting up and determining the initial wake-up reason, specified by the nextWR
script parameter in the script, which could be for either beacon reporting or data gathering. It then performs the corresponding task and goes to sleep until the next scheduled wake-up.
Upon waking up, the system updates the wake-up reason, schedules the next wake-up time based on the upcoming beacon or gather times, and repeats the process accordingly.
Pressing the button on the device will wake it up and send a beacon report immediately, regardless of the scheduled wake-up time. Note, that this doesn't affect the scheduled wake-up time, which will still occur as planned.
Communication with a broker diagram
The device periodically publishes a beacon message to the MQTT broker to indicate that it is operational and connected to the network. The beacon message is a short message that contains the device's status and information.
After the beacon is published, the device subscribes to the acrios/<IMSI>/up/#
topic to receive configuration and actions messages.
The device clears acrios/<IMSI>/up/config
message after applying the changes and publishes the changed parameters to the acrios/<IMSI>/config
topic.
The device executes the actions from the acrios/<IMSI>/up/action
topic. Actions can be scheduled to execute every time the device publishes the beacon message.
MQTT protocol
MQTT is a M2M/IoT connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport. It is useful for connections with remote locations where a small code footprint is required or network bandwidth is limited. The protocol allows devices to communicate with minimal overhead and low bandwidth.
MQTT broker
An MQTT broker is a server that receives all messages from the clients and then routes the messages to the appropriate destination clients. The broker is responsible for receiving all messages, filtering the messages, deciding who is interested in them, and then publishing the message to all subscribed clients.
MQTT client
An MQTT client is any device that runs an MQTT library and connects to an MQTT broker over a network. The client can be a publisher, a subscriber, or both.
Public HiveMQ MQTT broker
HiveMQ is a public MQTT broker that can be used for testing and development purposes. The broker is available at broker.hivemq.com. You can check messages from our testing device by subscribing to the topic acrios/230029530002847/#
.
- Navigate to HiveMQ browser client at www.hivemq.com/demos/websocket-client/.
- Connect to the broker by entering the server address
broker.hivemq.com
using default port8884
. - Subscribe to the topic
acrios/230029530002847/#
to receive messages from the device. - Check the messages from the device.
The broker.hivemq.com
is a public broker. This means that any data you publish or subscribe to is accessible by anyone connected to the broker. It is not recommended to use this for sensitive or confidential data, as there is no privacy or security guarantee. For production systems, consider using a secured and private MQTT broker.
Proceed with caution and ensure you are only testing or sharing non-sensitive information.
MQTT Broker setup
HiveMQ
Creating MQTT Broker
- Navigate to the HiveMQ Cloud at www.hivemq.com/products/mqtt-cloud-broker/ and click on Sign up free button.
- Create or log in to your account.
- Click on Create New Cluster button.
- Click on Create Serverless Cluster button.
info
HiveMQ also offers a paid Starter option with unlimited connections, better throughput, and more features.
- Click on Manage Cluster button.
- Navigate to the ACCESS MANAGEMENT tab to create credentials for the MQTT client.
On the OVERVIEW tab, you can find all the server addresses and ports for the MQTT client connection.
- Fill in the username and password and select appropriate permissions, then click on CREATE CREDENTIAL button.
- The credentials are created and can be used for the MQTT client connection.
Testing MQTT Broker
After creating the MQTT broker, you can test the connection using WEB CLIENT tab or the HiveMQ browser client.
- WEB CLIENT:
- Navigate to the WEB CLIENT tab, fill the credentials and click on Connect button.
- Scroll down to the Topic Subscription section and subscribe to the topic
#
. - Fill in the message and topic, then click on Send message button.
- Send messages should appear in the Messages section.
- Navigate to the WEB CLIENT tab, fill the credentials and click on Connect button.
- HiveMQ browser client:
- Navigate to the HiveMQ browser client, fill the host (cluster URL), username and password, then click on Connect button.
- Click on the Add New Subscription button.
- Fill in the topic
#
and click on Subscribe button. - Fill in the message and topic, then click on Publish button.
- Send messages should appear in the Messages section.
- Navigate to the HiveMQ browser client, fill the host (cluster URL), username and password, then click on Connect button.