Gemalto is now part of the Thales Group, find out more.

You are here

Thales IoT Developer Community

MQTT example using AT commands

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

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

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

EXS62/82, TX62/82 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 Hive MQ Broker:
http://www.mqtt-dashboard.com/ 
   
prepare the TX62 module

AT+cpin?
AT+cmee=2
AT+cereg=4
AT^SCFG="MEopMode/PwrSave","disabled"
at^smoni

prepare the rx connection "Subscribe"

AT+CGDCONT=1,"IPV4V6","iot.1nce.net"
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://developer.gemalto.com/tutorial/data-transfer-methods-mqtt-essentials
https://developer.gemalto.com/tutorial/data-transfer-methods

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

mpetschke