Hi.
I have the following code working with the SIM5218 cookings-hacks gprs/3G/GPS board. (see code below)
The next problems I could use some help with:
-
I would like the system to loop with an interval of 20 seconds and then updateing GPS data on a mysql server, using php.
-
The program stops after the the first connection and reception of data, I don't understand why the main loop stops? I'm probably missing something?
-
Is there a more elegant way to call the GPRS module? Perhaps I can use "timer interrupt" to call the different AT request on the module. So I won't have to use delays?
-
In the end, I would like the system to be aware of the current connection status, so it won't try to request a webpage if the connection is lost, Any suggestions in this direction would be greatly appreciated!
These questions is not a “write the code for me” request , more a “guide me please”.
This question is also threaded in the cooking-hacks forum: http://www.cooking-hacks.com/forum/viewtopic.php?f=20&t=3191&sid=3eddf42d567a8c7ca0fb555678054ee7
Thanks
Christian
the code:
char data[1024];
int data_size;
int led = 13;
int onModulePin = 2; // the pin to switch on the module (without press on button)
//int Omgang = 1;
int x = 0;
char server[ ]="**********.**"; //server address, replaced the sensitive data with ****** in examble
char port[ ]="80";
void switchModule(){
digitalWrite(onModulePin,HIGH);
delay(2000);
digitalWrite(onModulePin,LOW);
}
void setup(){
Serial.begin(115200); // UART baud rate
delay(2000);
pinMode(2, OUTPUT);
pinMode(led, OUTPUT);
pinMode(onModulePin, OUTPUT);
switchModule(); // switches the module ON
switchModule();
for (int i=0;i< 5;i++){
Serial.print("Giro numero: "); //Wait for the module to be ready
Serial.println(i);
delay(5000);
}
// Input Pincode for Simcard
Serial.println("AT+CPIN=****");
Serial.write (13);
delay(8000);
//Serial.flush();
while(Serial.read()!='K');
//check if the module is there?
Serial.println("AT");
Serial.write (13);
delay(1000);
//Serial.flush();
while(Serial.read()!='K');
Serial.println("Module is there!");
delay(500);
Serial.println("AT+CGSOCKCONT=1,\"IP\",\"bredband.tre.dk\"");
Serial.write (13);
//Serial.flush();
while(Serial.read()!='K');
} // End setup
void loop()
{
Serial.print("AT+CHTTPACT=\""); //Connects with the HTTP server
Serial.print(server);
Serial.print("\",");
Serial.println(port);
Serial.write(0x1A);
Serial.flush(); // not sure if necessary
do{
while(Serial.available()==0);
data[x]=Serial.read();
x++;
}
while(!(data[x-1]=='T'&&data[x-2]=='S')); //waits for response "REQUEST"
// Make the request on the server, replaced the sensitive data with ****** in examble
// request "data.php" on server .
// send the variable "Navn" with value of "Bird" to the PHP script
Serial.println("GET http://www.**********.**/data.php?Navn=Bird HTTP/1.0");
Serial.println("Host: www.************.**");
Serial.println("Content-Length: 0");
Serial.write(0x0D);
Serial.write(0x0A);
Serial.write(0x1A); //sends ++
while(Serial.read()!='K');
while(Serial.read()!=' ');
do{
while(Serial.available()==0);
data[x]=Serial.read();
x++;
}
while(!(data[x-1]=='/'&&data[x-2]=='<')); //Program stops at first occurence of "</"
Serial.println(data);
while(1);
}
The above code produces the following output (in the serial monitor / generated by the php script on the server ).
+CHTTPACT: REQUESTDATA,212
http/1.1 200 ok
date: thu, 30 aug 2012 13:18:04 gmt
server: apache
x-powered-by: php/5.3.16
connection: close
content-type: text/html
Successful
Bird
<a href='insert.php'>Back to main page</