Arduino Sim900 problems accessing the database

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’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();
  Serial.println("------------------");
  Serial.println();

  // 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://josepmorarduino.epizy.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

<?php
    
    $db['default']['dbdriver']='mysqli';
    $dbusername = "epiz_23486849";  
    $dbpassword = "*************";  
    $server = "sql307.epizy.com"; 
    $My_db = "epiz_23486849_arduino1";
        	
    // Connect to your database
    $dbconnect = mysql_pconnect($server, $dbusername, $dbpassword);
        
    $dbselect = mysql_select_db("epiz_23486849_arduino1",$dbconnect);
        
    // Prepare the SQL statement
    $sql = "INSERT INTO pes (Value_1, Value_2) VALUES ('".$_GET["data1"]."','".$_GET["data2"]."')";    
        
    // Execute SQL statement
    mysql_query($sql);

    ?>

I put the php file in the folder “htdocs”.

My account details are as follow:

  • Main Domain: mkvatcdx.epizy
  • FTP hostname: ftpupload
  • FTP username: epiz_23486849
  • MySQL hostname: sql307.epizy
  • MySQL username: epiz_23486849
  • Hosting Volume: vol6_3

I also have created a website here: http://josepmorarduino.epizy.com as it shows in my account.

I think the trouble I’m experiencing is related to the arduino code, but I don’t really know whats the problem I’m having. Is josepmorarduino.epizy not the one I should be pointing at in the code?

My database has 4 columns: ID; Date_Time, Value_1, Value_2
The tutorial I followed was https://www.youtube.com/watch?v=LgGOpLnzSns but it is not in the same hosting environment.
If you feel like I missed any piece of information let me know.

Any help or guidance will be greatly appreciated. Thank you for reading.

Hi
https://infinityfree.net/support/connecting-to-mysql-from-elsewhere/
https://infinityfree.net/support/javascript-error-using-api-or-mobile-android-app/

1 Like

okay thank you!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.