-->
Page 1 of 1

Posting sensor data to a php webpage _$GET

PostPosted: Wed Sep 07, 2016 1:49 pm
by lasse.h.knudsen
Greetings,

I want to add sensor data to a mysql database, and it works from a browser, my problem is i have trouble creating the "web request" that i need to do.
The sensor data comes from a DHT22 sensor, i was able to post to "thing speak" before i modified the sketch :) the sensor is reading correctly

serial output

0 Temperature: 21.80
0 Humidity: 72.20
0 VCC: 3.19
WiFi Client connected
Entering deep sleep
So the data is present.

if i just use this the "fake" data is being inserted into the SQL database, so i know the PHP part is working
Code: Select allhttp://192.168.1.250/default.php?sensor=havestue&temp=23.1&hum=60.3&voltage=3.32


And in the webserver i can see that its being contacted
from apache2 access.log
"
127.0.1.1:80 192.168.1.93 - - [07/Sep/2016:20:22:11 +0200] "GET /default.php?sensor=havestue&temp=21.40&hum=73.20&voltage=3.19" 200 0 "-" "-"
"
modified thingspeak code
Code: Select all if (client.connect(server, 80)) { // use ip 184.106.153.149 or api.thingspeak.com
   Serial.println("WiFi Client connected ");
   
   String postStr;
   postStr += "?sensor=";
   postStr += String(sensorname);
   postStr += "&temp=";
   postStr += String(temp);
   postStr += "&hum=";
   postStr += String(hum);
   postStr += "&voltage=";
   postStr += String(vcc);
   postStr += "\r\n\r\n";
   
   client.print("GET /default.php");
   client.print(postStr);
   client.print(" HTTP/1.1\n");
   client.print("Host: 192.168.1.250\n");
   client.print("Connection: close\n");
   client.print("Content-Type: application/x-www-form-urlencoded\n");
   client.print("Content-Length: ");
   client.print(postStr.length());
   client.print("\n\n");
  // client.print(postStr);
   delay(500);
   
   }//end if
   sent++;
 client.stop();


I guess my forming of the request is all off, Can anyone help me figure out where i have screwed up?

Best Regards
Lasse

Re: Posting sensor data to a php webpage _$GET

PostPosted: Thu Sep 08, 2016 1:57 pm
by lasse.h.knudsen
Greetings,

i managed to solve the problem myself, by using

String postStr;
postStr += "http://192.168.1.250/default.php?sensor=";
postStr += String(sensorname);
postStr += "&temp=";
postStr += String(temp);
postStr += "&hum=";
postStr += String(hum);
postStr += "&voltage=";
postStr += String(vcc);
//postStr += "\r\n\r\n";


HTTPClient http;

//http.begin("http://192.168.1.250/default.php?sensor=havestue&temp=23.1&hum=70.3&voltage=3.32"); //HTTP
http.begin(postStr); //HTTP

-Lasse

Re: Posting sensor data to a php webpage _$GET

PostPosted: Sat Jul 01, 2017 6:33 pm
by hickse
Can you share your *.ino and *.php code?