This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

nRF9160: Serial LTE modem + MQTT publish

Hi

This question is based on the NCS tag v1.8.0.

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

I got OK if I send a plain text to AWS. But I got an ERROR when I try to send message in JSON format like example above.

2022-01-25T08:22:14.024Z DEBUG modem << #XMQTTCON: 1,"nrf9160_Thing","MY_ENDPOINT-ats.iot.us-west-2.amazonaws.com",8883,16842753
2022-01-25T08:22:14.027Z DEBUG modem << OK
2022-01-25T08:22:28.864Z DEBUG modem >> AT#XMQTTPUB="topic/test","Test message with QoS 1",1,0
2022-01-25T08:22:28.885Z DEBUG modem << OK
2022-01-25T08:25:18.424Z DEBUG modem >> AT#XMQTTPUB="topic/test" {"msg":"Test Json publish"}
2022-01-25T08:25:18.435Z DEBUG modem << ERROR
2022-01-25T08:25:18.436Z ERROR Error: AT#XMQTTPUB="topic/test" {"msg":"Test Json publish"}
 failed

Does anyone know the right format to send JSON format AT command to serial LTE modem in v1.8.0?

Best regards,

Tim

  • Hi Tim,

    The correct way should be like the following steps:

    1. AT#XMQTTPUB="nrf91/slm/mqtt/topic0"  #enable slm data mode

    2. {"msg":"Test Json publish"}    # json format content, could be data in any format

    3. +++    #Exit slm data mode. Link Monitor attaches CRLF always, this will not stop slm data mode, use serial terminals like use Teraterm, Termite on Windows and Cutecome on Ubuntu, they support sending only +++. 

    Best regards,

    Charlie

  • Hi Charlie,

    Thanks for your reply. I finally figured out why Link Monitor keeps sending me timed-out ERROR after I enabled data mode.Sweat smile

    Best regards,

    Tim

     

  • Hi Charlie,

    May I ask you some questions about MQTT message in JSON format?

    1. Could I adjust the QoS level when I'm going to enable slm data mode?
    2. I got an issue like below(JSON format content was divided into two separate messages) if I run my python code in high frequency(about once per second).

    import serial
    
    ser = serial.Serial()
    ser.baudrate = 115200
    ser.port = 'COM3'
    
    # Connecting code...
    
    message = {'timestamp': TIMESTAMP, 'pulse': PULSE, 'spo2': SPO2}
    message_json = json.dumps(message).encode("ascii")
    ser.write(message_json)


    Is there anything I can do to prevent this problem?

    Best regards,

    Tim

  • Hi Tim,

    1. AT#XMQTTPUB="nrf91/slm/mqtt/topic0",,2,0 # You can keep second parameter empty and configure the third option for QoS.

    2. You need to add a proper delay between two messages depending on your network environment and message length(which affects time length for data transmassion). If your application needs a very high-frequency data update rate, you have to think about other solutions.

    Best regards,

    Charlie

  • I appreciate your help very much.

    Sincerely,

    Tim

Related