I have a problem with my code, it is supposed to open a url to a database and insert the variables in the database. I have already created the database and it works manually.
The code worked only one time and inserted the variables but it didn't work again and gives me an error. I haven't done anything to it then suddenly it worked again and I don't know how!! Please help me, I don't know what to do and I have a deadline.
#include <SoftwareSerial.h>
//(set up a SoftwareSerial instance called mySerial)
SoftwareSerial SIM900(2, 3);
char URL[200]="AT+HTTPPARA=\"URL\",\"http://www.mostafafouda.com/its/de.php?lat=1&lon=5";
//(add the reading to this character array - dtostrf?)
void setup() {
SIM900.begin(19200);
SIM900power();
Serial.begin(19200);
Serial.print("power up" );
delay(20000);
SIM900.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");//setting the SAPBR, the connection type is using gprs
delay(1000);
ShowSerialData();
SIM900.println("AT+SAPBR=3,1,\"APN\",\"etisalat\"");//setting the APN, the second need you fill in your local apn server
delay(4000);
ShowSerialData();
SIM900.println("AT+SAPBR=1,1");//setting the SAPBR, for detail you can refer to the AT command mamual
delay(2000);
ShowSerialData();
SIM900.println("AT+HTTPINIT"); //init the HTTP request
delay(2000);
ShowSerialData();
SIM900.println(URL);// setting the httppara
delay(1000);
ShowSerialData();
SIM900.println("AT+HTTPACTION=0");//submit the request
delay(10000);//the delay is very important, the delay time is base on the return from the website, if the return datas are very large, the time required longer.
ShowSerialData();
SIM900.println("AT+HTTPREAD");// read the data from the website you access
delay(300);
ShowSerialData();
SIM900.println("");
delay(100);}
void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
digitalWrite(9, HIGH);
delay(1000);
}
void ShowSerialData()
{
while(SIM900.available()!=0)
Serial.write(char (SIM900.read()));
}
void loop()
{
// Serial.println("SubmitHttpRequest - started" );
// SubmitHttpRequest();
// Serial.println("SubmitHttpRequest - finished" );
}