Example of HTTP Post request for sending json data

Wireless communications in Waspmote, topologies, node types...
Post Reply
seeker
Posts: 11
Joined: Fri Jun 10, 2016 8:56 am

Example of HTTP Post request for sending json data

Post by seeker » Thu Jun 16, 2016 8:18 am

Hi,

Can you please post an example program for sending JSON data through HTTP Post request, using GRPS ?

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Example of HTTP Post request for sending json data

Post by libelium-dev » Thu Jun 16, 2016 12:55 pm

Hi,

Here is the example to make a HTTP POST request, we don't use the JSON format to send data so we dont know if it will work.
http://www.libelium.com/development/was ... with-post/

Also you can try opening a TCP connection.
http://www.libelium.com/development/was ... onnection/

Regards

seeker
Posts: 11
Joined: Fri Jun 10, 2016 8:56 am

Re: Example of HTTP Post request for sending json data

Post by seeker » Fri Jun 17, 2016 12:39 pm

Nevermind, I programmed the server to work with www-formurlencoded data. Thanks anyways! :)

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Example of HTTP Post request for sending json data

Post by libelium-dev » Fri Jun 17, 2016 1:17 pm

You're welcome!

Carlosrod298
Posts: 2
Joined: Fri Aug 23, 2019 9:47 pm
Company: Unicauca

Re: Example of HTTP Post request for sending json data

Post by Carlosrod298 » Mon Aug 26, 2019 6:14 pm

I made this code for sending in json format

void SendHttpData(){
//////////////////////////////////////////////////
// 1. Switch ON
//////////////////////////////////////////////////
error = WIFI_PRO.ON(socket);
if (error != 0)
{
USB.println(F("1. WiFi did not initialize correctly"));
ErrCount++;
}
else
{
// 2. Set url
error = WIFI_PRO.setURL( type, host, port, url );
if (error == 0)
{ USB.println(F("2. setURL OK"));
}
else
{
USB.println(F("2. Error calling 'setURL' function"));
WIFI_PRO.printErrorCode();
}
//Set content Type
error = WIFI_PRO.setContentType(ContentType);
// check response
if (error == 0)
{
USB.println(F("2. setContentType OK"));
}
else
{
USB.println(F("2. Error calling 'setContentType' function"));
WIFI_PRO.printErrorCode();
}


//////////////////////////////////////////////////
// 3. Join AP
//////////////////////////////////////////////////
// check connectivity
status = WIFI_PRO.isConnected();
// Check if module is connected
if (status == true)
{
USB.println(F("3. WiFi is connected OK"));

USB.println(body);

////////////////////////////////////////////////
// 3.1. http request
////////////////////////////////////////////////
error = WIFI_PRO.post(body);
// check response
if (error == 0)
{
USB.print(F("3.1. HTTP POST OK. "));
USB.print(F("HTTP Time from OFF state (ms):"));

USB.print(F("\nServer answer:"));
USB.print(F(WIFI_PRO._buffer,WIFI_PRO.length)
}
}

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Example of HTTP Post request for sending json data

Post by libelium-dev » Tue Aug 27, 2019 8:33 am

Thanks for your contribution to the forum.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests