I have a question.
I am trying to setup simple server, that will be sending data from sensors to mySQL. Path /bezp/data.php?temperature="number" is working, when I do it in web brower. Also I can see text "connected" in serial monitor, so it enters IF, but database still wont update.
Arduino Code:
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {192, 168, 1, 101 }; //Enter the IP of ethernet shield
byte serv[] = {192, 168, 1, 16} ; //Enter the IPv4 address
EthernetClient cliente;
void runWebSetup() {
Ethernet.begin(mac, ip);
}
void runWebLoop(float temp) {
if (cliente.connect(serv, 80)) { //Connecting at the IP address and port we saved before
Serial.println("connected");
cliente.print("GET /bezp/data.php?"); //Connecting and Sending values to database
cliente.print("temperature=");
cliente.print(temp);
cliente.stop(); //Closing the connection
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
delay(5000);
}
Also temperature sensor is working and I am calling functions in another file.
CodePudding user response:
You never finished the request contents - you are sending only half an HTTP request.
You are sending this:
"GET /bezp/data.php?temperature=123"
But a valid request looks like this:
"GET /bezp/data.php?temperature=123 HTTP/1.0\r\n\r\n"
for HTTP 1.0
"GET /bezp/data.php?temperature=123 HTTP/1.1\r\nHost: 192.168.1.16\r\n\r\n"
for HTTP 1.1.
You have to send the method followed by path and protocol and CRLF, then any headers (each ending with CRLF), then another CRLF.
You were missing protocol, (maybe header(s)) and CRLFs.
See docs.