i have an Uno Wifi Rev2 and 5 sensors attached to it. The sensors work perfectly and the Uno is connected to my Wifisignal (WIFININA library).
I want to send the sensordata to a SQL database i have created in my domain. For this i created an php file in my domain which i can feed data, by sending it POST commands. I have tested the php file by use of a standalone POST tool and it works perfect (table in database gets filled with the test data i send)
Now i want to send the sensordata to the php. Therefore i have to use a POST command in my Arduino code. I'm having trouble getting this done.
A POST request does not involve a protocol OR a server. You have already connected to the server.
I am not connected to the server (someserver.nl) that has the php code on it. I want to send it to the code by use of POST.
I have used Curl to test my php file and that command is: curl -X POST -i 'http://someserver.nl/post-esp-data.php?...
I have to point the POST command to the server that has the php file on it... How else?
i see what you are trying to say. Believe me when is say i have spent talking to Mr google and looking on this forum for three days in a row now. As stated: i am a beginner at this. And this beginner is completely lost. That is why i use this forum to get back on track.
I do thank you for your pointers and the help you give here. But not everyone is a couchpotato that asks (evidentely) simple questions...
I do hope someone else remembers his/her starting days being frustrated :o of the fact that all the code you've read and tried doesn't work?
The code i am using is in this tutorial. When i use the httpclient i get errors, i assume that this library is not compatible with the uno wifi rev2 and so i am trying to get around this by typing a post command fully...
Perhaps i am writing gibberish, that would explain a lot! A link of where i can read the right stuff will really be enough.
The following library can be installed using the IDE Library manager and includes a simple POST example. I tried the example with a MKR1010/WiFiNINA and it works. It should work on other boards using the WiFiNINA library (and maybe Adafruit's airlift fork).
The simple POST example modified to work with a public HTTP test server named httpbin.org.
/*
Simple POST client for ArduinoHttpClient library
Connects to server once every 30 seconds, sends a POST request
and a request body
created 14 Feb 2016
modified 22 Jan 2019
by Tom Igoe
this example is in the public domain
Modified to work against httpbin.org. The equivalent POST using curl is:
curl --data "arg1=value1&arg2=value2" --verbose http://httpbin.org/post
The response body contains JSON showing the values and headers received by the httpbin
server. Example follows.
making POST request
Status code: 200
Response: {
"args": {},
"data": "",
"files": {},
"form": {
"arg1": "value1",
"arg2": "value2"
},
"headers": {
"Content-Length": "23",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "Arduino/2.2.0"
},
"json": null,
"url": "https://httpbin.org/post"
}
*/
#include <ArduinoHttpClient.h>
#include <WiFiNINA.h>
#include "arduino_secrets.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
/////// Wifi Settings ///////
char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASS;
const char serverName[] = "httpbin.org"; // server name
int port = 80;
WiFiClient wifi;
HttpClient client = HttpClient(wifi, serverName, port);
int status = WL_IDLE_STATUS;
void setup() {
Serial.begin(115200);
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to Network named: ");
Serial.println(ssid); // print the network name (SSID);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);
}
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
}
void loop() {
Serial.println("making POST request");
String contentType = "application/x-www-form-urlencoded";
String postData = "arg1=value1&arg2=value2";
client.post("/post", contentType, postData);
// read the status code and body of the response
int statusCode = client.responseStatusCode();
Serial.print("Status code: ");
Serial.println(statusCode);
String response = client.responseBody();
Serial.print("Response: ");
Serial.println(response);
Serial.println("Wait 30 seconds");
delay(30000);
}