I have an Arduino Mega 2560 and a SIM900 GSM GPRS Shield.
This is my first project with a database and I’m trying to post some values into it. I’ve followed a lot of tutorials on youtube but with no success.
I used this tutorial in this particular case https://www.youtube.com/watch?v=LgGOpLnzSns
I’m trying to apply here one of the codes I found wich included an arduino code:
#include <SoftwareSerial.h>
SoftwareSerial gprsSerial(10, 11);
void setup()
{
gprsSerial.begin(19200);
Serial.begin(19200);
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\",\"movistar.es\"");
delay(2000);
toSerial();
delay(2000);
// bearer settings
gprsSerial.println("AT+SAPBR=1,1");
delay(2000);
toSerial();
// bearer settings
gprsSerial.println("AT+SAPBR=2,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\",\"http:surrogate-benefits.000webhostapp.com/write_data.php?data1=2.88&data2=2.93\"");
delay(5000);
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();
delay(2000);
gprsSerial.println("");
gprsSerial.println("AT+HTTPTERM");
toSerial();
delay(300);
gprsSerial.println("");
delay(10000);
}
void toSerial()
{
while(gprsSerial.available()!=0)
{
Serial.write(gprsSerial.read());
}
}
and also had a write_data.php to upload to the /public_html folder in the File Manager.
<?php
$db['default']['dbdriver']='mysqli';
$dbusername = "id8785728_arduino";
$dbpassword = "xxxxxxxxxxxxxxxxxxxxxxxx";
$server = "localhost";
$My_db = "id8785728_arduino";
// Connect to your database
$dbconnect = mysql_pconnect($server, $dbusername, $dbpassword);
$dbselect = mysql_select_db("id8785728_arduino",$dbconnect);
// Prepare the SQL statement
$sql = "INSERT INTO pes (Value_1, Value_2) VALUES ('".$_GET["data1"]."','".$_GET["data2"]."')";
// Execute SQL statement
mysql_query($sql);
?>
My database has 4 columns: ID; Date_Time, Value_1, Value_2
and my website is surrogate-benefits.000webhostapp
If you feel like I missed any piece of information let me know.
Any help or guidance on to why it is not working and I’ll do my best to try to solve it…Thank you for reading.