1

I want to try entering data into the 000webhost server. In my case study, I use arduino uno, GSM sim900, and GPS module. all went well and there was no error on the GSM. Likewise, the GSP can easily get the latitude and longitude. When you want to send data to the server there is an error is at AT + CIPSEND. So the data cannot enter the 000webhost server. Is there something wrong with my code? there is my arduino ide code

void setup()
{
  Serial.begin(9600);   
  SIM900.begin(9600);  
  delay(100);
  Serial.println("Initializing...");
  delay(1000);
  SIM900.println("AT");
  updateSerial();
  SIM900.println("AT+CPIN?");
  updateSerial();
  SIM900.println("AT+CREG?");
  updateSerial();
  SIM900.println("AT+COPS?");
  updateSerial();
  SIM900.println("AT+CGATT?");
  updateSerial();
  SIM900.println("AT+CIPSHUT");
  updateSerial();
  SIM900.println("AT+CIPMUX=0");
  updateSerial();
  SIM900.println("AT+CGATT?");
  updateSerial();
  SIM900.println("AT+CSTT=\"airtelgprs.com\"");
  updateSerial();
  SIM900.println("AT+CIICR");
  delay(2000);
  updateSerial();
  SIM900.println("AT+CIFSR");
  updateSerial();
  SIM900.println("AT+CIPSPRT=0");
  delay(3000);
  updateSerial();
  SIM900.println("AT+CIPSTART=\"TCP\",\"xxxxx.000webhostapp.com\",\"80\"");
  delay(3000);
  updateSerial();
  Serial.begin(9600);
 gpsSerial.begin(9600);
}

void updateSerial()
{
  delay(500);
  while (Serial.available()) 
  {
    SIM900.write(Serial.read());
  } 
  while(SIM900.available()) 
  {
    Serial.write(SIM900.read());
  }
}
 
void loop()
{
    while(1)
  {
   while (gpsSerial.available() > 0)
    { gps.encode(gpsSerial.read()); }
      if (gps.location.isUpdated())
      {
       latitude=gps.location.lat();
       longitude=gps.location.lng();
       break;
      }
 }
   Serial.println("LATITUDE=" + String(latitude,6));
   Serial.println("LONGITUDE=" + String(longitude,6));
   delay(1000);
  SIM900.println("AT+CIPSEND");
  delay(10000);
  updateSerial();
  String str="GET /coba.php?latitude=" + String(latitude) + "&longitude=" +String(longitude);
  Serial.println(str);
  SIM900.println(str);
  updateSerial();
  SIM900.println(" HTTP/1.1\r\n");
  delay(4000);
  updateSerial();
  SIM900.println("Host: xxxx.000webhostapp.com");
  updateSerial();
  SIM900.println((char)26);
  delay(5000);
  SIM900.println();
  updateSerial();
  SIM900.println("AT+CIPSHUT");
  delay(100);
} 

Nana
  • 33
  • 5

1 Answers1

0

Is there something wrong with my code?

Yes, using delay like that is very, very, very, very wrong. You MUST read and parse everything the modem sends back to you. Nothing else will work reliably.

Without this fundamental issue resolved it is impossible to infer anything with regards to failures.

hlovdal
  • 26,565
  • 10
  • 94
  • 165