0

I'm following a guide on storing sensor data to MYSQL:

Guide

I'm using different sensors but my POST request is getting any results to my server. For now, I'm only storing temperature.

Here is my code for saving data:

void sendData(double input){

String data = "sensorid=3000000&temp=" + doubleToString(input, 2) + "&hum=1.2";

if(client.connect("192.168.1.50",80)){
    client.println("POST /arduino/add.php HTTP/1.1");
    client.println("Host: 192.168.1.50");
    //client.println("User-Agent: Arduino/1.0");
    //client.println("Connection: close");
    client.println("Content-Type: application/x-www-form-urlencoded");
    client.print("Content-Length: ");
    client.print(data.length());
    client.println();
    client.print(data);

    Serial.println("Sent data: " + data);
}

if(client.connected()){
   client.stop(); 
}
delay(300000);
}

I've commented out two headers since it did not give any other results. My Serial.println gives: Sent data: sensorid=3000000&temp=24.00&hum=1.2 Which means that the arduino is connected to the giving IP-adress and that my Request data is as I want. They are also working perferct when I'm testing with Requestmaker. So I'm pretty sure my error comes from the way I'm doing the request here.

So do you have any idea how I can solve this? Or how I can debug it t

  • There needs to be an empty line between the headers and the body of the request. Therefore you have to println() (not print()) the end of the last header. – Edgar Bonet Mar 1 '15 at 13:37
  • Try to use print() with '\n' at the end (only a newline, not carriage return. xportSendTextNoLine("C192.168.200.136/80\n"); sprintf(request,"GET /debug.php?dat=%u HTTP/1.0\n\n",value); xportSendTextNoLine(request); <-- This worked for me. But you'll have to change it a bit to arduino code. – Paul Apr 3 '15 at 7:22
  • did you solve this problem. I am having exactly the same issue and came to the same conclusion: the error comes from the way I am doing the request from the arduino. – mvcharcos Feb 7 '16 at 20:32
  • yes, the first comment was the solution to my problem. End with println instead of print. Could not mark it as answer since it was only a comment. – Ruben Ravnå Feb 7 '16 at 20:36
0

Answered by Edgar Bonet

There needs to be an empty line between the headers and the body of the request. Therefore you have to println() (not print()) the end of the last header.


Please accept this answer so the system knows it is the correct one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.