Milesight gateways not only have embedded network server, but also acts as MQTT client. Being so, we can transmit data that are collected from LoRa end-devices to a remote MQTT server that has previously been hosted by yourself.
Being a MQTT client to the server and a gateway to end-devices, Milesight gateway communicates bi-directionally, which especially requires LoRa end-devices under gateway to have their own pre-defined topics.
As the picture shown below, Milesight gateway defines topics set A on behalf of UC11xx, end-devices connected to LoRaWAN gateway, for MQTT server and client simulators to subscribe and read data. On the other way, client simulators and MQTT server publish messages to topics set B that have pre-defined format in UC11xx. For gateway with firmware 184.108.40.206 and above, gateway defines topics set C that modify downlink topics to a custom one. The new downlink topic includes “$deveui” as wildmask to appoint messages to a certain device.
Q: Where can I configure this service?
A: “Network Server>Application”. Create an application and save. You can go further on “Application>Data Transmission” and add an MQTT service. Transmitting data via HTTP or HTTPS is another optional transmission type and can be added in parallel with MQTT service. (For HTTP and HTTPS FAQ, check out this article and this article.)
Q: What should I put in the configuration after type chosen as MQTT?
A: “General”, “User Credentials”, “TLS”, “Topic” are all left blank initially. Under “General”, it’s supported to put in both WAN and LAN IP in “MQTT Server Address”. The port for MQTT service is 1883 for default, but you can put in other port, too. Connection Timeout sets the maximum response time that the client waits for the response from the server. If the client does not get a response after the maximum response time, it's determined that the connection has broken. Keeping Alive Interval defines the interval that Milesight gateways send heartbeat packets to MQTT server regularly to keep alive. “User Credentials”, “TLS” should be corresponding to the MQTT server configuration. Under “Topic” there is where we define topics set A and C on behalf of LoRa end-devices.
Q: Does Milesight gateway start to report messages as soon as the configuration is done correctly?
A: Yes. If you couldn’t read messages subscribing to correct topics after everything is saved and applied, you should be checking:
- Connection between Milesight gateway and MQTT server. Milesight gateways should be able to ping MQTT server on “Maintenance>Tools>Ping”. If Milesight gateway is on the same subnet as MQTT server is, check if their default gateway permits such communication. If MQTT server has a public IP, check if Milesight gateway has been granted Internet access.
- Topics set A. Under “Topic”, there are 5 types of data. “Uplink data” stands for all uplinks, for example we can use “milesight/uplink”. And in the client simulator we subscribe to “milesight/uplink”, we are supposed to read all data received in Milesight gateway. As for “Downlink data”, “Join notification”, “ACK notification”, “Error notification” can all be left blank if it’s not specially needed. For instance, if we use “milesight/join” for “Join notification” and subscribe it in client simulator, we’ll receive a “join notification” message under “milesight/join” when a LoRa end-device joins the network.
Q: What do “Uplink data” and “Downlink data” mean?
A: Aside from server or other clients, data as in messages flow from end-devices to gateway and vice versa. Uplink data is the one comes from an end-device, downlink data is the one goes to it.
Q: What does the “Error” in “Error notification” mean? Is it a malfunctioning sign in LoRa communication?
A: It depends on how the end-devices define error. If a packet sending from end-devices is flagged error, Milesight gateway will transmit it as an error notification. In UC11 series, this happens usually when the payload is too long for its current configuration.
Q: Where on the web GUI can I see the status of MQTT client?
A: Right under the connection type MQTT for version 64 and above.
Q: If any error on the server side caused failure in connection, will Milesight gateway try to solve this problem by sending missed packets again?
A: Not for now (standard 220.127.116.11 and below). Standard Milesight gateway doesn’t save packets in buffer, but you can manage to develop a secondary application with Python.
Q: Milesight gateway has been connected to MQTT server as I can see it as a client. But why can’t I read any messages subscribing to topics set A?
A: As depicted in the topology, “UC11—>Milesight gateway-->MQTT Server-->Client simulator”, the server-simulator connection is the final step. In order to make Milesight gateway transmit data to MQTT server then to client simulator, there must be end-devices sending data to Milesight gateway. For how to add end-devices and read data, please refer to Chapter 4.1-4.4 in Milesight gateway User Guide for UG85/UG87.
Q: Messages have arrived in MQTT server. What’s the JSON format of data packets from Milesight gateway?
A: Contact us for detailed API and meta-data format.
Q: Your default data format is not compatible with my application. How can I change it?
A: On “Network Server>Application>Payload Codec” we provide to write custom decoding functions to change the JSON structure.