3 Replies - 265 Views - Last Post: 07 February 2018 - 01:55 PM

#1 Zamalkawy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 31-January 18

Sending data to web server by GSM Module sim 808

Posted 07 February 2018 - 08:21 AM

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);
?>


Is This A Good Question/Topic? 0
  • +

Replies To: Sending data to web server by GSM Module sim 808

#2 Zamalkawy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 31-January 18

Re: Sending data to web server by GSM Module sim 808

Posted 07 February 2018 - 08:22 AM

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);
?>

Was This Post Helpful? 0
  • +
  • -

#3 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14239
  • View blog
  • Posts: 57,130
  • Joined: 12-June 08

Re: Sending data to web server by GSM Module sim 808

Posted 07 February 2018 - 08:28 AM

Quote

I tested the codes but it didn't work

Would you be able to elaborate? Are there errors? Odd behavior? How did you test it?
Was This Post Helpful? 0
  • +
  • -

#4 Zamalkawy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 31-January 18

Re: Sending data to web server by GSM Module sim 808

Posted 07 February 2018 - 01:55 PM

View Postmodi123_1, on 07 February 2018 - 03:28 PM, said:

Would you be able to elaborate? Are there errors? Odd behavior? How did you test it?


I Compiled the Arduino code and it has no errors, and upload it to the Arduino , It is supposes to send values to the database but the database still empty, that is the problem.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1