Skip to main content
Andrea Ortogni
Associate
May 17, 2018
Question

SPWF04Sx HTTPOST command with JSON payload

  • May 17, 2018
  • 1 reply
  • 1496 views
Posted on May 17, 2018 at 10:27

Hi,

I'm using a SPWF04Sx WIFI module.

In AT.HTTPOST command there isn't a field for a JSON payload, but I really need it.

There is something that allow me to send a JSON payload ?

There isn't also a field for the call's header that i've to fill with a token. There is someone that can solve my problems?

Thanks in advance!

#json #spwf04sx #http-post
    This topic has been closed for replies.

    1 reply

    Elio Cometti
    Visitor II
    May 17, 2018
    Posted on May 17, 2018 at 11:27

    Hi,

    you have to save the JSON payload in a file with .json extension and specify that file name as last parameter of AT+S.HTTPPOST command.

    Regards,

    Elio
    Andrea Ortogni
    Associate
    May 17, 2018
    Posted on May 17, 2018 at 11:49

    Hi Elio,

    Can you make me an example of a .json file?

    it is like : 

    {

       'identifier':'centralina',

       'password':'password'

    }

    ?

    And the json file has to be saved in the WIFI module ? if it's so can you explain me how ?

    Elio Cometti
    Visitor II
    May 17, 2018
    Posted on May 17, 2018 at 14:04

    Hi,

    it's a regular text file containing JSON formatted data and named with .json extension.

    With your example you can type the following sequence into the serial console and get the data saved into example.json:

    AT+S.FSC=example.json,61<CR>{<CR><LF>   'identifier':'centralina',<CR><LF>'password':'password'<CR><LF>}

    AT-S.OK

    Now you can send your JSON object by AT+S.HTTPPOST. The following command send your post request to httpbin server to get it analyzed:

    AT+S.HTTPPOST=httpbin.org,/post,,,,,,example.json<CR>

    AT-S.Http Server Status Code:200

    {

       'args':{

       },

       'data':'{\r\n   \'identifier\':\'centralina\',\r\n   \'password\':\'password\'\r\n}',

       'files':{

       },

       'form':{

       },

       'headers':{

          'Connection':'close',

          'Content-Type':'application/json',

          'Host':'httpbin.org',

          'Transfer-Encoding':'chunked',

          'User-Agent':'HTTP-Client'

       },

       'json':{

          'identifier':'centralina',

          'password':'password'

       },

       'origin':'62.110.21.125',

       'url':'

    http://httpbin.org/post

    '

    }

    AT-S.OK