Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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" );
}
share|improve this question
    
Do you really want all those spaces in the URL? – Majenko Apr 30 '16 at 15:11
    
I am sorry the url is copied wrongly it must be mostafafouda.com/its/de.php?lat=3&long=2 you can put any number you want the spaces here was my mistake – nemo Apr 30 '16 at 15:15
    
please anyone help me It's very important and I don't know what to do – nemo May 1 '16 at 10:59
1  
Well, all you have said is "it gives an error". No mention of what that error might be. Help us to help you by telling us what the error is it gives you. – Majenko May 1 '16 at 11:01
    
okay the error at the command AT+HTTPREAD sometimes it shows error and sometimes it shows OK and don't give the respond of the page and also at the command httpPara It sometimes gives ok – nemo May 1 '16 at 11:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.