Search code examples
httparduinowebserversim800

SIM800L HTTP communication with web server


I'm using a SIM800L module and Arduino Uno to communicate with a web server. I have a sensor read by the Arduino. I want to store the sensor's value to my database.

On my web server I have a PHP page that saves data to the database. I'm using the GET method like this: http://www.isj.ir/Samples/sample.php?sen1=27.2.
I'm using this library for the SIM800L.

But I can't pass my sensor's value with this example. I'm so confused! Would you please help me and tell me what should I do?

sprintf(body, "{\"name\": \"%s\"}", "Arduino");
result = http.post("isj.ir/Samples", body, response);
Serial.println(body);
print(F("HTTP POST: "), result);
if (result == SUCCESS) {
    Serial.println(response);
    StaticJsonBuffer<32> jsonBuffer;
    JsonObject& root = jsonBuffer.parseObject(response);
    lastRunTime = millis();
    waitForRunTime = root["waitForRunTime"];
    print(F("Last run time: "), lastRunTime);
    print(F("Next post in: "), waitForRunTime);
}

result = http.get("isj.ir/Samples", response);
print(F("HTTP GET: "), result);
if (result == SUCCESS) {
    Serial.println(response);
    StaticJsonBuffer<32> jsonBuffer;
    JsonObject& root = jsonBuffer.parseObject(response);
    lastRunTime = millis();
    waitForRunTime = root["waitForRunTime"];
    print(F("Last run time: "), lastRunTime);
    print(F("Next post in: "), waitForRunTime);
}

Solution

  • for sending data using GET method use these AT Commands:

    AT+SAPBR=3,1,"CONTYPE","GPRS"
    AT+SAPBR=3,1,"APN","RighTel" // use your Operator  APN 
    AT+SAPBR=1,1
    AT+HTTPINIT
    AT+HTTPPARA="URL","http://yoursite.com?sen1=xxx&sen2=xxx&..."
    AT+HTTPACTION=0 //(0=GET,1=POST,2=HEAD)
    

    then you must see a massage like +HTTPACTION: 0,200,xxx with using this code:

     AT+HTTPREAD:0,xxx
    

    you can see result if your php code do something after process