void POSTxneelo() {
const char serverHost [] = "www.xxxxxxx.nom.za";
WiFiClient client;
const int httpPort = 80;
//Send an HTTP POST request
//Check WiFi connection status
if(WiFi.status()== WL_CONNECTED){
HTTPClient http;
if(!client.connect(serverHost, httpPort)) {
Serial.println ("Connection Failed");
return;
}
else {
Serial.println ("</br>>>> Connection SUCCEEDED....</br></br>");
}
// debug line checking to see if the data values are there
Serial.println ((String) "HTTP/1.1\r\nGET http://www.xxxxxxx.nom.za/php/weather_data/esp-post-data.php?" +
"&datadate=''" +
"&BMP_temp=" + temperature +
"&BMP_pressure=" + pressure +
"&DHT_temp=" + dhttemperature +
"&DHT_rh=" + dhthumidity +
"&DHT_absrh=" + dhtabsolute +
"&WIND_speed=" + 0 +
"&WIND_direction=" + 0 +
"&heat_index=" + dhtheatindex +
"&dew_point=" + dhtdewpoint +
"&comf_ration=" + dhtcomfort +
"&comf_percept=" + dhtperception +
"&DATA_record=''" +
"Host: " + serverHost + "\r\n" +
"Connection: close\r\n\r\n");
[COLOR=rgb(41, 105, 176)]/*
* // This will send the request to the server
* this little bit is just dropped off somewhere on some site to test if the connection works
* THIS LINE WORKS WHEN UNCOMMENTED AND THE NEXT ONE IS COMMENTED OUT
* client.print((String)"GET / HTTP/1.1\r\n" + "Host: " + String(serverHost) + "\r\n" + "Connection: close\r\n\r\n");
*/[/COLOR]
/* /// this sends the data to mysql* */
[COLOR=rgb(41, 105, 176)]// AT RUN TIME THE REMOTE APACHE SERVER GIVES A [B]400 ERROR : BAD REQUEST[/B]
// OTHERWISE THE SKETCH RUNS AND DROPS THROUGH TO THE LINES BELOW AND DISPLAYS THE RETURN FROM APACHE
// EVERYTHING ELSE WORKS EVEN THE php WHICH WRITES ZEROS TO THE DATABASE AT THE SAME TIME AS THE esp32 READS DATA AND
// TRIES TO SEND AND ADD TO THE DATABASE.
// SO THIS IS THE OFFENDING LINE
// THE STRING LOOKS CORRECT WHEN SENT TO THE SERIAL MONITOR
// IT FAILS WHETHER ITS A get OR A post[/COLOR]
client.print (String ("GET http://www.xxxxxxx.nom.za/php/weather_data/esp-post-data.php?") +
("&datadate=") + "" + <<-- that is dummy its a timestamp insertion by MYSQL
("&BMP_temp=") + temperature +
("&BMP_pressure=") + pressure +
("&DHT_temp=") + dhttemperature +
("&DHT_rh=") + dhthumidity +
("&DHT_absrh=") + dhtabsolute +
("&WIND_speed=") + 0 +
("&WIND_direction=") + 0 +
("&heat_index=") + dhtheatindex +
("&dew_point=") + dhtdewpoint +
("&comf_ration=") + dhtcomfort +
("&comf_percept=") + dhtperception +
("&DATA_record=") + "" + <<-- that also dummy its PRIMARY AUTO INCREMENT
"HTTP/1.1\r\n" +
"Host: " + serverHost + "\r\n" +
"Connection: close\r\n\r\n");
/**/
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis () - timeout > 10000) {
Serial.println ("</br></br>>>> Client Timeout !</br>");
client.stop();
return;
}
}
// read all the lines of the reply from the server get a return string as HTML displayed in serial monitor
while (client.available ()) {
String line = client.readStringUntil('\r');
Serial.print (line);
}
Serial.println ();
Serial.println ("CLOSING CONNECTION\r\n\r\n");
client.stop();
}
}