This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF91 Serial LTE modem MQTT AT command for JSON format

Hi 

I am using nRF9160DK SLM application to evaluate the MQTT AT command function.

Everything is fine if the MQTT message is the string type shown by the doc.

AT#XMQTTPUB="nrf91/slm/mqtt/topic0",1,"Test message with QoS 0",0,0

But when I send the message with JSON format, the console returns ERROR.

 

AT#XMQTTPUB="nrf91/slm/mqtt/topic0",2,"{"temperature":20,"value":80}",0,0

I also tried to add escape before double quotes inside the message, and it still failed.

Does anyone know the right format to send JSON format AT command to serial LTE modem?

Best regards,

Joseph

  • Hi! 

    I'm not able to test this at the moment, but your command should be correct.

    Which MQTT broker are you connecting to? Perhaps the payload is the problem.

    Best regards,

    Heidi

  • Hi 

    I tried two MQTT broker "mqtt.eclipse.org" and "broker.emqx.io" and the result are the same.

    I also tried to modify the double quote to single quite like "{'HR': 80, 'BR': 20}", SLM returns OK.

    I doubt it is AT command parsing issue.

    Please check my log. Thanks.

    2020-12-08T22:44:34.733Z DEBUG modem >> AT#XMQTTCON=1,"josephtest12345678","","","broker.emqx.io",1883
    2020-12-08T22:44:35.733Z ERROR Error: 'AT#XMQTTCON=1,"josephtest12345678","","","broker.emqx.io",1883
    ' timed out
    2020-12-08T22:44:37.348Z DEBUG modem << OK
    2020-12-08T22:44:38.012Z DEBUG modem << #XMQTTEVT: 0,0
    2020-12-08T22:44:49.431Z DEBUG modem << %CESQ: 56,2,21,3
    2020-12-08T22:44:51.004Z DEBUG modem << %CESQ: 55,2,27,3
    2020-12-08T22:44:56.636Z DEBUG modem >> AT#XMQTTPUB="josephtest/iot/data",1,"Test message with QoS 0",0,0
    2020-12-08T22:44:56.708Z DEBUG modem << OK
    2020-12-08T22:45:07.991Z DEBUG modem << %CESQ: 57,2,21,3
    2020-12-08T22:45:08.924Z DEBUG modem << %CESQ: 56,2,27,3
    2020-12-08T22:45:31.231Z DEBUG modem << %CESQ: 56,2,22,3
    2020-12-08T22:45:40.604Z DEBUG modem >> AT#XMQTTPUB="josephtest/iot/data",1,"Test message with QoS 0",0,0
    2020-12-08T22:45:40.672Z DEBUG modem << OK
    2020-12-08T22:45:40.768Z DEBUG modem << %CESQ: 56,2,27,3
    2020-12-08T22:45:52.309Z DEBUG modem << %CESQ: 57,2,21,3
    2020-12-08T22:45:55.006Z DEBUG modem << %CESQ: 56,2,27,3
    2020-12-08T22:46:01.946Z DEBUG modem << %CESQ: 55,2,21,3
    2020-12-08T22:46:07.805Z DEBUG modem << %CESQ: 55,2,26,3
    2020-12-08T22:46:27.640Z DEBUG modem >> AT#XMQTTPUB="josephtest/iot/data",2,"{\"HR\": 80, \"BR\": 20}",0,0
    2020-12-08T22:46:27.656Z DEBUG modem << ERROR
    2020-12-08T22:46:27.659Z ERROR Error: AT#XMQTTPUB="josephtest/iot/data",2,"{\"HR\": 80, \"BR\": 20}",0,0
     failed
    2020-12-08T22:46:41.842Z DEBUG modem >> AT#XMQTTPUB="josephtest/iot/data",2,"{"HR": 80, "BR": 20}",0,0
    2020-12-08T22:46:41.879Z DEBUG modem << ERROR
    2020-12-08T22:46:41.898Z ERROR Error: AT#XMQTTPUB="josephtest/iot/data",2,"{"HR": 80, "BR": 20}",0,0
     failed
    2020-12-08T22:46:42.043Z DEBUG modem << #XMQTTEVT: 9,0
    2020-12-08T22:46:56.887Z DEBUG modem >> AT#XMQTTPUB="josephtest/iot/data",2,"{'HR': 80, 'BR': 20}",0,0
    2020-12-08T22:46:56.957Z DEBUG modem << OK
    2020-12-08T22:47:57.089Z DEBUG modem << %CESQ: 56,2,21,3
    2020-12-08T22:47:57.886Z DEBUG modem << %CESQ: 56,2,27,3
    2020-12-08T22:47:58.205Z DEBUG modem >> AT#XMQTTPUB="josephtest/iot/data",2,"{'HR': 80, 'BR': 20}",0,0
    2020-12-08T22:47:58.266Z DEBUG modem << OK
    2020-12-08T22:47:58.844Z DEBUG modem << #XMQTTEVT: 9,0
    2020-12-08T22:48:09.750Z DEBUG modem << %CESQ: 57,2,21,3
    2020-12-08T22:48:10.683Z DEBUG modem << %CESQ: 56,2,27,3
    2020-12-08T22:48:15.793Z INFO Modem port is closed
    

  • Hi!

    Okay, I see the problem now. 

    You need to escape the double quotation marks in the payload, like this:

    AT#XMQTTPUB="nrf91/slm/mqtt/topic0",2,"{\"temperature\":20,\"value\":80}",0,0

    Best regards,

    Heidi

  • Hi Heidi

    I tried escape before, please see my prior log.

    I have traced the source code and found that FW didn't handle the escape double quotation.

    The AT command will be split into many small pieces string because of the double quotation in the payload even I add escape.

    Although I can fix this problem by modifying the SLM source code, is it possible that Nordic developer can fix the problem in next release. Thanks.

    Bye the way, I use nRF Connect SDK v1.4.0.

  • Hi Joseph,

    Currently only hex string or plain text datatype are supported:

    • 0 - hexidecimal string (e.g. “DEADBEEF” for 0xDEADBEEF)

    • 1 - plain text (default value)

    Please use  hexidecimal string as datatype. For example:

    Replace AT#XMQTTPUB="nrf91/slm/mqtt/topic0",2,"{"temperature":20,"value":80}",0,0

    as:

    AT#XMQTTPUB="nrf91/slm/mqtt/topic0",0,"7b2274656d7065726174757265223a32302c2276616c7565223a38307d",0,0

    Best Regards,

    Larry

Related