Arduino UNO Wifi - http post request (JSON)

Hello,

I need to send the data captured from arduino uno wifi to the server using http post (REST) request.
Would like to understand the options available to trigger http post request (rest) other than "ciao" for "Arduino UNO Wifi".

Appreciate your soonest reply.

Thanks

you can change the firmware to WiFi Link. I made the Uno WiFi a usable board with Serial1 library

Thanks Juraj,

How to perform a POST request and pack the parameters (JSON) in request body.

Also i am unable to compile the code, below is the error details,
Board selected = Arduino Uno Wifi

WiFiLinkWebClient:21: error: within this context
WiFi.init(&Serial1);
^

WiFiLinkWebClient:21: error: no matching function for call to 'WiFiClass::init(UnoWiFiDevEdSerial1*)'
WiFi.init(&Serial1);

Thanks

did you change the firmware?

do not use the WiFi Link library version 1.0 from Library Manager with Serial1. use the github version 1.1 referred in Serial1 readme and WiFi Link firmware readme

I need to update the firmware with this "arduino-firmware-wifilink/ArduinoFirmwareEsp at master · JAndrassy/arduino-firmware-wifilink · GitHub" before uploading?

I will try with the new 1.1 currently it is installed 1.0.1 from the library manager. I cannot find 1.1 in the lib manager.

UNO WiFi with WiFi Link firmware

suneelng:
I cannot find 1.1 in the lib manager.

only arduino.org repository maintainer can publish new version of this library. but there is no one for now.

I replaced the Wifilink and it builds now.

  1. I first need to flash the firmware from this git "arduino-firmware-wifilink/ArduinoFirmwareEsp at master · JAndrassy/arduino-firmware-wifilink · GitHub".

  2. Upload the wifilinkwebclient to the board.

  3. Could you help how to trigger a post request with paramters (json).

thanks

yes

WiFiLinkWebClient example from Uno_WiFi_Developer_Edition_Serial1 is working? prints the logo?

your server is ready? what is the url? do you have an example of the json string?

Flashed the firmware (the above git)

Uploaded the wifiLinkWebClient code,

i see the program freezes at the below line.

while (WiFi.status() != WL_CONNECTED) {
delay(10);
}

did you configure WiFi Link with WebPanel?

yeah it is configured and an ip address is also assigned.

Still it does not work. :frowning:

make please a screenshot of WebPanel for me

attached the screen shot

looks good. and can you show me your config.h from firmware?

config.h

/*

  • Firmware version and build date
    */

#define BUILD_DATE "20170509"
#define FW_VERSION "1.0.1"
#define FW_NAME "wifilink"

/*

  • Define board model name
    */

//#define STAROTTO
//#define PRIMO
#define UNOWIFIDEVED
//#define UNOWIFI

/*

  • Enable/Disable Debug
    */

//#define DEBUG
//#define BAUDRATE_DEBUG 115200

/*

  • Define board hostname
    */

#define DEF_HOSTNAME "arduino"

/*

  • Defines the communication channel between microcontroller
  • and esp82266, with concerning parameters
    */

//#define HOSTNAME "arduino" //used by mdns protocol

#if defined(STAROTTO)
//Arduino STAR OTTO configuration parameters
#define BOARDMODEL "STAROTTO"
#define ARDUINO_BOARD "star_otto" //mdns
#define ESP_CH_UART
#define BAUDRATE_COMMUNICATION 460800
#define WIFI_LED 14
#define SSIDNAME "Arduino-Star-Otto"
#elif defined(PRIMO)
//Arduino PRIMO configuration parameters
#define BOARDMODEL "PRIMO"
#define ARDUINO_BOARD "primo" //mdns
#define ESP_CH_SPI
#define WIFI_LED 2
#define SSIDNAME "Arduino-Primo"
#elif defined(UNOWIFI)
//Arduino PRIMO configuration parameters
#define BOARDMODEL "UNOWIFI"
#define ARDUINO_BOARD "unowifi" //mdns
#define ESP_CH_SPI
#define WIFI_LED 2
#define SSIDNAME "Arduino-Uno-WiFi"
#elif defined(UNOWIFIDEVED)
//Arduino UNO WIFI DEV. EDITION configuration parameters
#define BOARDMODEL "UNOWIFIDEVED"
#define ARDUINO_BOARD "unowifi" //mdns
#define ESP_CH_UART
#define BAUDRATE_COMMUNICATION 19200
#define WIFI_LED 14
#define SSIDNAME "Arduino-Uno-WiFi"
#endif

not the right wifilink. use 1.1.0 from here. how did you end up with 1.0.1? have I someware in docs a wrong link?

Works fine now, thanks :slight_smile:

Not sure, i think i had a copy of older version before and i did not make it point to verify with the new link, my bad.

Regarding the post request, say we have the api similar to this here.

It takes below parameters and also returns the same.
{
"ID": 0,
"UserName": "string",
"Password": "string"
}

Thanks

post request

  if (client.connect(server, 80)) {
    client.println("POST /api/Users HTTP/1.1");
    client.print("Host: ");
    client.println(server);
    client.println("Connection: close");
    client.println();
    client.println(data);
  }

to build json string you can use ArduinoJson library (is in Library Manager with examples)

or build the string with sprintf

	char data[50];
	sprintf(data, "{\"i\":%i,\"t\":%lu,\"v1\":%d,\"v2\":%d,\"c\":%u}", ix, events[ix].timestamp, events[ix].value1, events[ix].value2, events[ix].count);

(it is a snippet from my project)

Thanks it works.

Have a question,

code snippet:

char data[100];
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root["ID"] = 10;
root["UserName"] = "user1";
root["Password"] = "123456";
sprintf(data, "{"ID":10,"UserName":"user1","Password":"123456"}");

Serial.println("Connected to server");
client.println("POST /api/Users HTTP/1.1");
client.println("content-type: application/json");
client.print("content-length: ");
client.println(strlen(data));
client.print("Host: ");
client.println(server);
client.println("Connection: close");
client.println();
// root.prettyPrintTo(client);
// client.println();
client.println(data);

  1. The code works fine if i send the json object store in data.
  2. But it does not work when i use the root variable. I use the below code lines to post data,
    root.prettyPrintTo(client);
    client.println();
  3. how can i extract only the data part from the response and discard other headers section.

Thanks