0

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);
}
gre_gor
  • 6,669
  • 9
  • 47
  • 52

2 Answers2

5

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

1

so , in server side i use this code to store sensors data to MySql Database.

<?php
$servername = "localhost";
$username = "admin";
$password = "#admin#";
$dbname = "admin";


  $sen1 = $_GET['sen1'];
  $sen2 = $_GET['sen2'];
  $sen3 = $_GET['sen3'];
  $sen4 = $_GET['sen4'];
  $sen5 = $_GET['sen5'];
  $sen6 = $_GET['sen6'];
  $sdate = $_GET['sdatetime'];

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "INSERT INTO SensorTable (sen1, sen2, sen3,sen4,sen5,sen6,sdatetime)
VALUES ('$sen1','$sen2','$sen3','$sen4','$sen5','$sen6','$sdate')";

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

i can fill my table by this code in any browser address bar.

isj.ir/Samples/sample.php?sen1=1&sen2=5&sen3=10&sen4=15&sen5=20&sen6=33&sdatetime=20171211

at now i looking for some way that send that by SIM800L. ( and arduino UNO ). how can i change sensor's value? and how can i send with SIM800L

isj.ir/Samples/sample.php?sen1=1&sen2=5&sen3=10&sen4=15&sen5=20&sen6=33&sdatetime=20171211

thanks.