Thales' cellular IoT products business is now part of Telit Cinterion, find out more.

You are here

Telit Cinterion IoT Developer Community

MQTT example using AT commands

Tutorial, March 24, 2021 - 2:28pm, 6159 views

MQTT over AT example for EXS62/82, TX62/82, PLS63/83

There are fairly cheap SIM data plans on the market that enable low data rate connectivity such as MQTT nearly without life time constraints. For NBioT/CatM we use 1NCE SIM here, which offers 10 years connectivity including 500MB data for only 10€ once!

EXS62/82, TX62/82, PLS63/83 and other modules have built in MQTT client.

Here is a code snippet for receiving/transmitting messages with a public server. We use a free HiveMQ Broker:
http://www.mqtt-dashboard.com/ 
   
prepare the TX62 module

AT+cpin?
AT+cmee=2
AT+cereg=4       //for EXS62/82   or AT+cereg=2 for PLS63/83
AT^SCFG="MEopMode/PwrSave","disabled"
at^smoni

prepare the rx connection "Subscribe"

AT+CGDCONT=1,"IPV4V6","iot.1nce.net"              // or e.g. "web.vodafone.de"
AT^SISS=1,"conId","1"
AT^SISS=1,"address","mqtt://3.126.241.146:1883"   // broker.hivemq.com:1883
AT^SISS=1,"cmd","subscribe"
AT^SISS=1,"keepalive",180             <--- keep the connection for 3 min
AT^SISS=1,"topicQos","1"
AT^SISS=1,"clientid","uniqueID1234"
AT^SISS=1,"topicfilter","cmnd"        <--- MQTT topic filter
AT^SISC=1                             <--- just to make sure 
AT^SICA=1,1

AT^SISO=1,2                           <--- open connection to server
...now we are waiting for messages
^SISR: 1,1                            <--- data received
...and fetch the data with
AT^SISR=1,100
^SISR: 1,5
Test1                                 <--- received message: cmnd/Test1 
OK
^SISR: 1,1

Transmit a message: "Publish"

These commands are for use from an existing "subscribe" connection as described above.

AT^SISD=1,"setParam",cmd,"publish"
AT^SISD=1,"setParam",Qos,"1"
AT^SISD=1,"setParam",Retain,"1"
AT^SISD=1,"setParam",Topic,"cmnd"     <--- MQTT topic prefix
AT^SISD=1,"setParam",hcContent,"Test1"<--- message

AT^SISU=1                             <--- send MQTT message

We don't close the connection because we want to stay subscribed for a while.

Please find more detailed information here:

https://iot-developer.thalesgroup.com/tutorial/data-transfer-methods-mqt...
https://iot-developer.thalesgroup.com/tutorial/data-transfer-methods

https://iot-developer.thalesgroup.com/tutorial/how-do-mqtt-exs82-platform

Hey there, thanks for the tutorial! 

I am quite new with AT commands so sometimes I get lost with the details. When I try to run the tutorial I get "+CME ERROR: operation failed" when I do AT^SISS=1,"conId","1" . My understanding is that I have to setup a profile but I am not sure if thats the problem? 

I have the 1nce card, network is connected (with data) and the EXS62 module on a LGA Devkit. Any idea what I might be doing wrong?

Any help would be super appreciated, thank you! 

I figured it out! 

You should add the following AT command before AT^SISS=1,"conId","1" for it to work. All it ***** is the srvType to be defined first :) 

AT^SISS=1,srvType,"mqtt" 

Cheers!

Author

mpetschke's picture
mpetschke