How to Subscribe MQTT Messages from LoRa Server¶
In the LoRaWAN application framework, MQTT is wildly used. For example, your LoRa node devices send sensor data to a gateway and the gateway forward these data to a cloud server, how can we get these sensor data from the cloud server?
The purpose of this article is to provide some examples of how to get MQTT messages from a cloud servers. Hope these examples can provide some reference or make sense to your application.
The four keys to success MQTT subscription: 1. Host address, 2. Host port; 3. user name/pass word, 4. MQTT Topic.
Here is a simple python3 example that can be used to subscribe to MQTT messages from the server.
In the simple python example, the content in the three red boxes needs to be modified according to your actual situation:
username_pw_set– The MQTT topic subscribe user name and pass word.
For HT-M02 PoE Edge LoRa Gateway, the default user name is
loraroot, pass word is
For Heltec LoRa Cloud Server, the login information is the user name and password of the MQTT subscription.
subscribe– MQTT topic name, in the example code, the
2is application ID allocation by server.
PORT– MQTT server address and communication port.
Run it in a shell with Python3, the content with red line is the data send by node. It’s encrypted in BASE64 format
If the example does not run correctly, may be missing related components, install it through the following command.
sudo pip3 install paho-mqtt python-etcd
Via third party application (MQTT.fx)¶
There are many useful MQTT subscription and push software on the Internet. This article takes MQTT.fx as an example.
Basic communication can be carried out with the above settings. And then click
Scanin turn, and wait for the connected node to transmit data.
After the node uploads the data, the information will be scanned in the
Select one as the subscription information. When there is matching subscription information uploaded, it will be displayed in the data column. The sample subscription is