MQTT Flex with LARA-R6, SARA-R5 and SARA-R422

Our first release of MQTT Flex utilises the DTLS support within the native MQTT-SN client on the u-blox LARA-R6, SARA-R5 and SARA-R422x modules.


For SARA-R5, "00B" module versions are not supported. "01B" or newer modules with at least firmware version 03.14,A00.01 are needed. For SARA-R422x, a SARA-R422S or SARA-R422M8S module with firmware version 00.12,A00.00 or newer is needed.

You can follow the instructions in the AT Commands Manual for how to use the MQTT-SN Client and security profiles.:

Some simple examples to get you up and running quickly are listed below.

Configure the module

  • Specify the client key and certificate to be used

    This example assumes you have saved the client key and certificate generated by the Thingstream platform for your F
    lex Thing to the file system of the SARA module using the AT+UDWNFILE command using the file names device.pem for the certificate and device.key for the key.

    AT+USECMNG=1,1,"MQTTFlex_cert","device.pem"

    AT+USECMNG=1,2,"MQTTFlex_key", "device.key"

  • Configure the DTLS security profile

    The following commands set up the DTLS security profile which the MQTT-SN client will make use of.

    Set the profile ID to use. This examples uses profile 0:
    AT+USECPRF=0
    Set the certificate validation level:
    AT+USECPRF=0,0,0
    Set profile 0 to accept TLS v1.2:
    AT+USECPRF=0,1,3
    Set the cipher suite:
    AT+USECPRF=0,2,99,"C0","30"
    Set the client key and certificate to be used (as created in the previous step):
    AT+USECPRF=0,5,"MQTTFlex_cert"
    AT+USECPRF=0,6,"MQTTFlex_key"

  • Configure the MQTT-SN client to use your MQTT Flex thing with the security profile

    Set the client ID (copy from Thingstream portal):
    AT+UMQTTSN=0,"device:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    Configure the MQTT-SN gateway endpoint:
    AT+UMQTTSN=1,"mqtt-flex.thingstream.io",2443
    Set the client to use the required DTLS profile:
    AT+UMQTTSN=9,1,0

  • Save configuration

    AT+UMQTTSNNV=2

  • Load configuration

    AT+UMQTTSNNV=1

Using the MQTT-SN Client

Once you have completed the MQTT-SN client configuration, you will need to set up the packet switched data configuration to use the APN specified by your MNO. You can then proceed with the MQTT-SN commands e.g.


  • 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