1

I'm trying to post data to my SQL database and it seems that I'm not sending the data correctly. My PHP file is working since I have tried it and it writes to the database.

I am getting an esp.find("SEND OK") but I must be sending it wrong or something.

Here is the code: DT 0050 - GLASSES - from sun to sound - chk oil filter malibu old or new?

void loop() {
    // call sensors.requestTemperatures() to issue a global temperature
    // request to all devices on the bus
    Serial.print(" Requesting temperatures...");
    sensors.requestTemperatures();  // Send the command to get temperatures
    char tempC = sensors.getTempCByIndex(0);
    char buffer[10];
    Serial.println("DONE");
    Serial.print("Temperature for Device 1 is: ");
    // You can have more than one IC on the same bus. 
    // 0 refers to the first IC on the wire
    Serial.print(sensors.getTempCByIndex(0));   // "byIndex"
    delay(5000);
    data = "temperature=" + tempC;  // d
    httppost();
    delay(1000);
}

void httppost() {
    esp.println("AT+CIPSTART=\"TCP\",\"" + server + "\",80");   //start a TCP connection.
    if (esp.find("OK")) {
       Serial.println("\r\nTCP connection ready");
    }
    delay(1000);
    String postRequest =
        "POST /http://manilla.technoaid.net/esp8266.php HTTP/1.1\r\n"
        "Host: 66.96.134.25\r\n" "User-Agent: Arduino/1.0\r\n"
        "Connection: close\r\n"
        "Content-Type: application/x-www-form-urlencoded\r\n"
        "Content-Length: \r\n" "data";
    **String sendCmd = "AT+CIPSEND=";
    esp.print(sendCmd);
    esp.println(postRequest.length());
    delay(1000);
    if (esp.find(">")) {
        Serial.println("Sending..");
        esp.print(postRequest);
        if (esp.find("SEND OK")) {
            Serial.println("Packet sent");
            while (esp.available()) {
                String tmpResp = esp.readString();
                Serial.println(tmpResp);
            }
            // close the connection
            esp.println("AT+CIPCLOSE");
        }
    }
}
  • 2
    Your **String and your empty Content-Length look suspicious. Also, there should ne \r\n\r\n between the headers and the actual data. – Edgar Bonet Feb 6 '17 at 18:57

Your Answer

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

Browse other questions tagged or ask your own question.