MQTT

From BoSL Wiki
Jump to navigation Jump to search

MQTT is a lightweight protocol for sending messages over the internet. This page describes how to use MQTT with the BoSL ecosystem.

BoSL nano

The AT commands for MQTT can be found at this link. The key AT commands needed are: To connect to the mqtt server:

AT#XMQTTCON=1,"client_id","username","password","domain_name",1883

Where client_id is the name up the client publishing the material, it can be chosen by the uploader. username and password are the mqtt login credentials (if required) otherwise these can be empty (""). The domain_name is the domain name or IP address of the mqtt server, 1883 is the mqtt port, 1833 is a typical value for this. To publish a message:

 AT#XMQTTPUB="topic","the message which i want to send",QoS,retain

Where topic is the topic you want to send the message to. QoS = 0, 1, or 2 is the Quality of Service and indicates how much effort the publish will take to ensure the message is received . retain = 0, or 1 is a flag to the mqtt broker than indicates if the message should be retained. A value of 1 should be used for logging with the BoSL broker. The actually message is limited to 1024 bytes. The connection can then be closed with the command:

AT#XMQTTCON=0

An example upload script is provided here: File:Bosl nano mqtt example.ino

BoSL Board

For the BoSL board, an example script which publishes to an MQTT server is provided: File:BoSLboard mqtt example.ino

Testing

BoSL nano

The BoSL nano was set up in a long term test with this File:Bosl nano mqtt example.ino file. The sensor logged from 2023-04-29 to 2023-06-05 on a single battery. Over this time 700 49110 logs were performed without resetting or stopping (1 minute logging interval). 1 in every 151 logs were skipped though this skipping rate was less towards the beginning became larger as the battery depleted. For the blue 4-cell 10000 mAh battery used a rate of 150 logs/mV was found, or approximately 0.1 mAh/log. The mqtt protocol data usage is 100 bytes per log. Of the skipped logs 25 were due to AT+CGDCONT=0,"IP","simbase" not returning OK; 1 was due to failure to register to the network (AT+CREG?); 290 were due to AT#XMQTTCON=1,"CLIENTID","USERNAME","PASSWORD","DOMAINNAME", 1883 not successfully connecting to the MQTT server; and 7 were due to AT#XMQTTPUB=... failing or the MQTT publish request failing.


More results on the BoSL nano are now available. For pure logging (with no sensor), the overall log failure rate was 2%, however the sensor was able to log for 55000 logs without any user intervention needed (until battery flat). Of the failed logs 82% were caused by AT#XMQTTCON=1 (connecting to MQTT server), a futher 7% by AT#XMQTTPUB (sending data to MQTT server), 11% was AT+COPS or AT+CEREG (failure to register to network).

For radar logging, the overall log failure rate was 5%, however the sensor was able to log for 26000 logs without any user intervention needed (until battery flat). Of the failed logs 66% were caused by AT#XMQTTCON=1 (connecting to MQTT server), a futher 5% by AT#XMQTTPUB (sending data to MQTT server), 30% was AT+COPS or AT+CEREG (failure to register to network).


BoSL Board rev 0.4.x

The BoSL board radar logging was less reliable under the current implementation of MQTT, the log success rate was about 2/3, with 9000 logs performed with no intervention on a single battery.