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

  • 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