0

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

Guide

My POST request isn't 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 given IP-adress and that my request data is as I want. They are also working perfectly when I'm testing with Requestmaker, so I'm pretty sure my error comes from the way I'm doing the request here.

Do you have any idea how I can solve or debug this?

ocrdu
1,7953 gold badges12 silver badges24 bronze badges
asked Mar 1, 2015 at 7:27
4
  • 1
    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. Commented Mar 1, 2015 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. Commented Apr 3, 2015 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. Commented Feb 7, 2016 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. Commented Feb 7, 2016 at 20:36

1 Answer 1

1

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.

ocrdu
1,7953 gold badges12 silver badges24 bronze badges
answered Feb 7, 2016 at 22:06

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.