Go Down

Topic: [solved] arduino send data to mysql db using gsm/GPRS shield 2 (Read 29080 times) previous topic - next topic


I've read tons of tutorials and topics... maybe now i'm confused.
only one target:
send a data(integer) from arduino to mysql db host by a free hosting service ( altervista) and save it in a table/column.

already server up and test the mysql db / php script in this way:
php code:

Code: [Select]

"attenzione non è possibile connettersi al server <br />".mysql_error());
echo (
"Connesso con successo");
print (
"Connesso con successo");}

$db mysql_select_db("my_sqldb"$conex);

"attenzione, non è possibile connettersi al database <br />".mysql_error());

//$Boton = $_POST["strBoton"];
$Boton $_GET["strBoton"];

$sql "INSERT INTO test2 (test) VALUES ('".$Boton."') ";   

$res mysql_query($sql,$conex);


now insert this adress im my browser:
Code: [Select]
the data 976 is correctly load by my sql db, nice one.

arduino side make me stupid:
here i have try tons of solution and now i'm confusing a lot.
i'm going to reduce day after day the code in order to have the more EASY example i hope, my code now is this:

Code: [Select]

// libraries
#include <GSM.h>

// PIN Number
#define PINNUMBER ""

// APN data
#define GPRS_APN       "tre.it" // replace your GPRS APN
#define GPRS_LOGIN     ""    // replace with your GPRS login
#define GPRS_PASSWORD  "" // replace with your GPRS password

// initialize the library instance
GSMClient client;
GPRS gprs;
GSM gsmAccess;

// URL, path & port
char server[] = "mysite.altervista.org";
char path[] = "/write_data2.php";
int port = 80; // port 80 is the default for HTTP

//The variable that will have the data as a string to send it, i read sending an int with POST may cause trouble
//String strBoton = "";
void setup(){
  // initialize serial communications and wait for port to open:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only

  Serial.println("Starting Arduino Web Client.");
  // connection state
  boolean notConnected = true;

  // After starting the modem with GSM.begin()
  // attach the shield to the GPRS network with the APN, login and password
    if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
      notConnected = false;
      } else
      Serial.println("Not connected");


void loop(){
  //convert the button state in string to send it
  //strBoton is the variable that the GET method will search for
  // if you get a connection, report back via serial:
  if (client.connect(server, port))
    Serial.println("conected and sending data");

    // Make a HTTP request:
 client.print("GET /write_data2.php?strBoton=66");
 client.println(" HTTP/1.1");
 client.println("Host: www.mysite.altervista.org");
 client.println("Connection: close");
    // if you didn't get a connection to the server:
    Serial.println("the connection failed");
  delay(10000); // delay to send data every 10 seconds

the serial monitor output:
Code: [Select]
Starting Arduino Web Client.
conected and sending data
the connection failed

there is a hi probability that in the milion of test i lost some step, my help request is this:
see the php working code and the nonworking sketch, someone can tell me the easy example to access my sqldb and send data passing from my php script?


Sorry sorry sorry...
my phone provider need a umts comunication protocol, so today i have tested with my broder's sim and it work.
what confused me is that i'm able to send SMS so i think  "ergo can connect correctly to internet" but is not the same.

for the future people that can encounter the same problem:

be sure that your phone provider support a only GSM internet access and don't need a UTMS one!

sorry for inutile question


would you please tell about the sql? how many column does it contain?



please code software serial arduino uno and SIM 900 GPRS with schematic diagram
to run this link :"http://localhost/workfile/dht.php?temperature=20"

Go Up