MQTT-SN with SARA-R5 and SARA-R422

BETA Available now for trials and POC


We are excited to make available support for MQTT Anywhere using a Thingstream SIM and the native MQTT-SN client on the SARA-R5 and SARA-R422 modules.


For SARA-R5, firmware version 02.05 is needed. For SARA-R422, firmware version 00.08 is needed.


This is a beta release and currently has the following known limitations:


  • MQTT-SN QoS -1 is not yet supported

  • MQTT-SN clean session = false in not yet supported

  • MQTT-SN topic alias has a max of 2 digits at the moment so only the "self" alias (topic alias 1) can be used

  • MQTT-SN connection duration in seconds will be rounded up to the nearest minute on the broker

  • The maximum message size that can be sent is 1016 bytes


You can follow the instructions in the AT command manual for how to use the MQTT-SN Client. The SARA-R422 manual including the MQTT-SN details has not yet been released but the commands are the same on both modules. Some simple examples to get you up and running quickly are listed below.

For the fastest network registration on your Thingstream SIM, we suggest to set AT+URAT=9,7. This speeds up the network scan time by disabling NBIoT where there are very few available networks.


Setup


  • Set ClientID

    This needs to be a unique value for your Thingstream domain. We suggest using the Identity value of your SN Thing which you can find on the Thing
    Details page of the management console.

    AT+UMQTTSN=0,"identity:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

  • Set server IP address and port

    AT+UMQTTSN=2,”10.7.0.55”,2442

  • Set connection duration (seconds)

    AT+UMQTTSN=8,600

  • Save configuration

    AT+UMQTTSNNV=2

  • Load configuration

    AT+UMQTTSNNV=1

Using the MQTT-SN Client

Once you have completed the MQTT client configuration, you will need to set up the packet switched data configuration to use the TSUDP APN and you can proceed with the MQTT-SN commands.


  • Connect

    AT+UMQTTSNC=1
    Expect +UUMQTTSNC: 1,1 as a response to confirm you are connected. You should also see a green dot next to your Thing in the management console.



  • Register a topic

    Before you can publish to a normal topic, you need to register with with the broker and get back a topic ID.

    AT+UMQTTSNC=2,"my/publish/topic"
    Expect +UUMQTTSNC: 2,1,1 as a response to confirm the registration. The final argument in the response is the topic ID to use when you publish.


  • Publish

    AT+UMQTTSNC=4,1,0,0,0,"1","My message"

    Expect +UUMQTTSNC: 4,1 as a response to confirm the publish. You will also now see a new device originated message in the activity tab for your Thing in the management console.



To receive messages on your module, you need to subscribe to a topic.


  • Subscribe

    AT+UMQTTSNC=5,1,0,"my/subscribe/topic"
    Expect +UUMQTTSNC: 5,1,0,1 as a response to confirm you have subscribed. You will also now see a new subscription in the activity tab for your Thing in the management console.


Now if you publish a message to "my/subscribe/topic " you will see it arrive on the module. You can use the "Send Message" function in the management console to send a test message. Check out the guide here to see how.


  • Read a received message

    When the message arrives, you'll see
    +UUMQTTSNC: 9,1 in the terminal. You can read the message with the following command.

    AT+UMQTTSNC=9,1




In this section

SDK


Related content

MQTT Beginners Guide

IoT Communication-as-a-Service plans

SARA-R5 AT Commands Manual

Thingstream Management Console


Still need help?

If you need more help or have any questions, please send an email to support@thingstream.io.