Hi all
I'm trying to send any simple data from GSM Module sim 808 wired by Arduino uno to web server.
I created a database on the web server and PHP file to receive the data from Arduino .
I tested the codes but it didn't work and I don't know what's wrong?.
I Appreciate your help.
Thanks in advance.
Arduino code
#include <SoftwareSerial.h>
SoftwareSerial gprsSerial(0, 1);
void setup()
{
gprsSerial.begin(9600);
Serial.begin(9600);
Serial.println("Config SIM900...");
delay(2000);
Serial.println("Done!...");
gprsSerial.flush();
Serial.flush();
// attach or detach from GPRS service
gprsSerial.println("AT+CGATT?");
delay(100);
toSerial();
// bearer settings
gprsSerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
delay(2000);
toSerial();
// bearer settings
gprsSerial.println("AT+SAPBR=3,1,\"APN\",\"taif\"");
delay(2000);
toSerial();
// bearer settings
gprsSerial.println("AT+SAPBR=1,1");
delay(2000);
toSerial();
}
void loop()
{
// initialize http service
gprsSerial.println("AT+HTTPINIT");
delay(2000);
toSerial();
// set http param value
gprsSerial.println("AT+HTTPPARA=\"URL\",\"testsim808.000webhostapp.com/write_data.php?data1=2.88&data2=2.93\"");
delay(2000);
toSerial();
// set http action type 0 = GET, 1 = POST, 2 = HEAD
gprsSerial.println("AT+HTTPACTION=0");
delay(6000);
toSerial();
// read server response
gprsSerial.println("AT+HTTPREAD");
delay(1000);
toSerial();
gprsSerial.println("");
gprsSerial.println("AT+HTTPTERM");
toSerial();
delay(300);
gprsSerial.println("");
delay(10000);
}
void toSerial()
{
while(gprsSerial.available()!=0)
{
Serial.write(gprsSerial.read());
}
}
PHP Code
<?php
// Prepare variables for database connection
$dbusername = "id4660353_save"; // enter database username, I used "arduino" in step 2.2
$dbpassword = "123456789"; // enter database password, I used "arduinotest" in step 2.2
$server = "testsim808.000webhostapp.com"; // IMPORTANT: if you are using XAMPP enter "localhost", but if you have an online website enter its address, ie."www.yourwebsite.com"
$My_db = "id4660353_save";
// Connect to your database
$dbconnect = mysql_pconnect($server, $dbusername, $dbpassword);
$dbselect = mysql_select_db("id4660353_save",$dbconnect);
// Prepare the SQL statement
$sql = "INSERT INTO SAVE_DATA (Value_1, Value_2) VALUES ('".$_GET["data1"]."','".$_GET["data2"]."')";
// Execute SQL statement
mysql_query($sql);
?>