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

AT Commands for JSON POST (Serial LTE Modem) Example

I'm running the Serial LTE Modem firmware and utilizing the reference docs in the LTE Link Monitor Terminal (My commands in yellow, blue/grey text is response)

NCS 1.4, SLM firmware, https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/applications/serial_lte_modem/doc/HTTPC_AT_commands.html

AT+CFUN=1

OK

AT+CFUN?

<bunch good things showing its connecting>

AT#XHTTPCCON=1,"test.domain.com",5000

#XHTTPCCON:1

OK

AT#XHTTPCREQ="POST","/post2","Host: test.domain.com:5000\nAccept: */*\nContent-Type: application/jsonl charset=utf-8\nContent-Length: 34",34

OK

#XHTTPCREQ:1

#XHTTPCREQ:1

OK

\n{"key1":"value1", "keyZ":"valueZ"}

OK

AT#XHTTPCCON=0

#XHTTPCCON=0

OK

Ready

Now my server does not see the JSON payload, I've tried multiple things on #XHTTPCREQ:1, but my server is just seeing this as an attempt at a form submission without a proper data payload (at least my little python-based Flask echo server does).  This makes no sense to me as I specifically sent the content-type to be application/json.

Im trying to evaluate these boards as a drop-in replacement option for Digi LTE modems (We're consistently getting 28-300+ second connect time with Digi, and 3-6 second connect time with the NRF9160 chips) on a custom MCU board we're using, so the preference is to get an AT Command protocol in place as those MCUs already interface over AT commands.

I just want to get a "hello, world" equivalent working with JSON payload over HTTP before I start looking at HTTPS/MQTT options going forward.  Any help here would be greatly appreciated.

~Evan

Parents Reply Children
  • Can you please give me your list of AT commands in the LTE Link Monitor that successfully performs an HTTP POST with a JSON payload using the default Serial LTE Modem firmware?  This isn't a firmware issue, it's a documentation one.

    The documentation states a JSON payload can be sent, but the example (https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/applications/serial_lte_modem/doc/HTTPC_AT_commands.html) is for application/x-www-form-urlencoded data:

    AT#XHTTPCREQ="POST","/post","User-Agent: SLM/1.2.0
    Accept: */*
    Content-Type: application/x-www-form-urlencoded
    Content-Length: 20
    ",20
    OK
    #XHTTPCREQ: 1
    12345678901234567890
    OK
    #XHTTPCREQ: 0
    #XHTTPCRSP: 576,1
    HTTP/1.1 200 OK
    Date: Wed, 09 Sep 2020 08:21:03 GMT
    Content-Type: application/json; charset=utf-8
    Content-Length: 405
    Connection: keep-alive
    ETag: W/"195-JTHehAiV7LQRCKihfzcZBX1rgGM"
    Vary: Accept-Encoding
    set-cookie: sails.sid=s%3AtApCs6p2Ja2on5dYO8QvhQSEEfnvkjOX.31HKOpZcip6MzzUoqPw2WZib0rPpimc5y10Mjczukoc; Path=/; HttpOnly
    {"args":{},"data":"","files":{},"form":{"12345678901234567890":""},"headers":{"x-forwarded-proto":"https","x-forwarded-port":"443","host":"postman-echo.com","x-amzn-trace-id":"Root=1-5f589067-d61d0850c65f3568f9c9e050","content-length":"20",#XHTTPCRSP:165,0
    "user-agent":"SLM/1.2.0","accept":"*/*","content-type":"application/x-www-form-urlencoded"},"json":{"12345678901234567890":""},"url":"">https://postman-echo.com/post"}

    ~Evan
  • Hi,

    I'm not able to reproduce your issue because I'm getting #XHTTPCREQ: -128 when sending the JSON string.

    But I have contacted the developer who wrote the Serial LTE Modem application and I'll let you know when I hear back about the correct way to do this. 

    Best regards,

    Heidi

  • Apparently, there is some issue with the current SLM HTTP client service to send JSON format that's being worked on right now.

    I should have a working example for you tomorrow. 

  • Hi, support for JSON has been implemented in PR 4178.

    In LTE Link Monitor you need to use "\x0D\x0A" as the terminator, i.e hexadecimal carriage return and line feed characters. Make sure to add a terminator after the last line as well.

    Here is the example used in the documentation:

    AT#XHTTPCREQ="PUT","/iot/v1/device/12345678901","User-Agent: curl/7.58.0\x0D\x0A
    accept: */*\x0D\x0A
    CK: DEADBEEFDEADBEEFDE\x0D\x0A
    Content-Type: application/json\x0D\x0A
    Content-Length: 224\x0D\x0A
    ",224

    And then

      {"id":"123456789","name":"iamchanged","desc":"My Hygrometer","type":"general","uri":"http://a.b.c.d/hygrometer","lat":24.95,"lon":121.16,"attributes":[{"key":"label","value":"thermometer"},{"key":"region","value":"Taiwan"}]}

    Please let me know if you still have issues!

    Best regards,

    Heidi

  • Hi Evan,

    Would you be able to share the solution? I am also facing some problem with getting the HTTP request to work.

    Thanks!

Related