Difference between revisions of "MQTT"

From BoSL Wiki
Jump to navigation Jump to search
Line 9: Line 9:
 
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.
 
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:
 
To publish a message:
   AT#XMQTTPUB="topic","the message which i want to send",QoS , retain
+
   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. The actually message is limited to 1024 bytes. The connection can then be closed with the command:
 
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. The actually message is limited to 1024 bytes. The connection can then be closed with the command:
 
  AT#XMQTTCON=0
 
  AT#XMQTTCON=0

Revision as of 05:28, 13 April 2023

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. 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