cancel
Showing results for 
Search instead for 
Did you mean: 

SPMW01SA HTTP post with JSON format

reedomneck
Associate III
Posted on March 16, 2016 at 16:03

Hi All,

For my project i am using SPMW01SA WiFi module and still we are in development stage so we are doing our R&D on STEVAL-IDI004v2 evaluation board.

STEVAL-IDI004v2 board WiFi is able to connect to internet and when we are trying to send sensor data to cloud WiFi module is responding back with arguments are missing. 

Our cloud is expecting data in JSON format and HTTP post method.

Can anyone please help me on this.

Regards,

--Manz

#https://my.st.com/public/ste2eco
13 REPLIES 13
Posted on March 16, 2016 at 16:14

Hi,

you can try using FW3,5 and HTTPREQ command

BR

j

florian239955_st
Associate II
Posted on March 22, 2016 at 09:22

Hi Manz,

does it work with the new firmware?

Some of us are trying to send a http post to the Android GCM server, that also accepts posts in JSON format.

https://my.st.com/public/STe2ecommunities/interface/Lists/WiFi%20Modules/Flat.aspx?RootFolder=%2fpublic%2fSTe2ecommunities%2finterface%2fLists%2fWiFi%20Modules%2fHTTPPOST%20Example%20Android%20GCM&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800086789498A6852D4897EA192EB1DEE909&TopicsView=http...

But I still don't get it working. Maybe you can post the commands of your solution.

Cheers,

Flow

Posted on March 24, 2016 at 16:26

Hi Flow,

did you try something like this...?

u8 request[] = ''

POST /blog/postsAccept: application/jsonContent-Type: application/jsonContent-Length: 57{''title'':''Hello World!'',''body'':''This is my first post!''}

\r\n\r\n''

u8 command[] = ''at+s.httpreq=IP,port,sizeof(request)\r''

and issue command+request over module UART

j

florian239955_st
Associate II
Posted on March 25, 2016 at 09:30

Hi Jerry,

thanks for your example.

I tried a lot, but don't get the page to accept the content lenght:

I send:

AT+S.httpreq=android.googleapi.com,80,388

and after that I send the post data:

POST /gcm/sendAccept: application/jsonContent-Type: application/jsonContent-Length: 243 ... followed by the JSON content

I receive always the answer, that the length is required...

HTTP/1.0 411 Length Required

                                                  

Content-Type: text/html; charset=UTF-8

                                        

Content-Length: 1564

                                                          

Date: Fri, 25 Mar 2016 08:24:42 GMT

                                           

                                     

                                         

<!DOCTYPE html>

                                                                

                <html lang=en>

                                                 

                                 <meta charset=utf-8>

                          

                                                        <meta name=viewport cont

ent=''initial-scale=1, minimum-scale=1, width=device-width''>

                    

                                                              <title>Error 411 (

Length Required)!!1</title>

                                                    

                              <style>

                                          

                                          *{margin:0;padding:0}html,code{font:15

px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margi

n:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{backgr

ound:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-ri

ght:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:no

ne}a img{border:0}@media screen and (max-width:772px){body{background:none;margi

n-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/im

ages/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left

:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.

google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repea

t 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlel

ogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-dev

ice-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlel

ogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100

%}}#logo{display:inline-block;height:54px;width:150px}

                         

                                                         </style>

              

                                                                    <a href=//ww

w.google.com/><span id=logo aria-label=Google></span></a>

                      

                                                            <p><b>411.</b> <ins>

That’s an error.</ins>

                                                       

                           <p>POST requests require a <code>Content-length</code

> header.  <ins>That’s all we know.</ins>

    
Posted on March 25, 2016 at 09:45

Only for debug...

did you already tried to send nothing? I mean, using ''

Content-Length: 0

''
florian239955_st
Associate II
Posted on March 25, 2016 at 14:13

Hi Jerry,

I tried it... but I get the same response :\

Cheers,

Flow

Posted on March 25, 2016 at 14:20

Bad :(

My suggestion is to switch for a while from SPWF01S to a simple Netcat utility tool running on PC. Once request string is sane, you can switch again to module, and include that string...

I hope someone else can give you some useful information...

j

florian239955_st
Associate II
Posted on March 25, 2016 at 18:11

Hey J,

I played a little bit with wireshark.

I sniffed the packets send by my PC program, that works with gcm. I've seen there, that between the Content-xxxx messages are   \r\n.

So I tried this also with the SPWF. But when I have there  \r\n between e.g. ''Content-Type'' and ''Content-Length'', I didn't sniffer any HTTP packets any more, just tcp packets.

Without the  \r\n, I also sniffer HTTP packets send by the SPWF.

Do you have an idea why didn't sniff any HTTP packets when I have the  \r\n in my header?

Thx & regards,

Flow

0690X00000603OjQAI.jpg

0690X00000603OZQAY.jpg

Posted on March 29, 2016 at 11:03

Hi Flow,

no idea for this. Bytes you see in the wireshark, are the ones you fill in the module by HTTPREQ command. Module does not append nothing by itself.

Second picture shows a ''Truncated'' request. The string ''POST something HTTP/1.1'' is really ''POST something other...''. Seems like string provided to HTTPREQ is not well formatted. Try to sniff the UART link between module and external MCU. Try also to put a delay between HTTPREQ command's <CR> and following payload (request string), just to be sure that characters are not lost over serial line.

Let me know.

j