Chat freely about anything...

User avatar
By claus-lind
#68505 Hi all..
Now i must ask..

I am trying to post some temprature data on a mysql base on a webserver, using PUT and a php file.

I have this program running on an Arduino Uno with an ethernet shield, and am now trying to get it to work on ESP8266.

The reading of Dallas 18b20 is ok.
But when i try to post to the database it wont work.
The same PHP file is called.4
If i use "postman" in Chrome, using the 2 variables I have, data is posted ok.

Here is the Code and the serial monitor output i have tried to debug with..
I have hard coded the "datapost" so that i have this part at a fixed values.
Post DB is only called when u see :

"connected
tabel=fanger_bund&temp=13" in the serial monotir

Any ideas how to crack this ?

Best regards Claus Lind


//----------------------------------------------------------------------
// start post DB;
//----------------------------------------------------------------------
void post_to_db (String tabelnavn, DeviceAddress deviceAddress, DallasTemperature Pin) {
char temperatur_buffer[12];
String datapost;
char tempbuffer[12];
float number = Pin.getTempC(deviceAddress);
dtostrf(number, 2, 1, tempbuffer); // dtostrf=(x,W,P,x) Width= Characters including dot & minus sign. Precision= Characters after decimal point.
// datapost = "tabel=" + tabelnavn + "&temp=" + tempbuffer;
datapost = "tabel=fanger_bund&temp=13";

if (client.connect("x.y.z", 80)) { //My server adress
Serial.println("connected");
client.println("POST /add.php HTTP/1.1");
client.println("Host:x.y.z"); // SERVER ADDRESS HERE TOO
client.println("Content-Type: application/x-www-form-urlencoded");
client.print("Content-Length: ");
client.println(datapost.length());
client.println();
client.println(datapost);
Serial.println(datapost);
}
if (client.connected()) {
Serial.println("client disconnect");
client.stop(); // DISCONNECT FROM THE SERVER
}
}
// slut post DB



Responce from serial monitor
Connecting to Lind Access point
.
WiFi connected did it
Local IP address : 192.168.7.90
Connecting to 192.168.7.210
Connected ! PDU Length = 240
Temp C: 25.44
Temp C: 25.37
Temp C: 25.37
Temp C: 25.44
Temp C: 25.44
Temp C: 25.44
connected
tabel=fanger_bund&temp=13
Temp C: 25.44