3

I want to send data to my php server using sim900 module but I am unable to initialize http service on sim900.

code:

#include <SoftwareSerial.h>
SoftwareSerial gprsSerial(8, 9);

void setup()
{
  gprsSerial.begin(9600);
  Serial.begin(9600);

  Serial.println("Con");
  delay(2000);
  Serial.println("Done!...");
  gprsSerial.flush();
  Serial.flush();


  // See if the SIM900 is ready
  gprsSerial.println("AT");
  delay(1000);
  toSerial();

  // SIM card inserted and unlocked?
  gprsSerial.println("AT+CPIN?");
  delay(1000);
  toSerial();

  // Is the SIM card registered?
  gprsSerial.println("AT+CREG?");
  delay(1000);
  toSerial();

  // Is GPRS attached?
  gprsSerial.println("AT+CGATT?");
  delay(1000);
  toSerial();

  // Check signal strength
  gprsSerial.println("AT+CSQ ");
  delay(1000);
  toSerial();

  // Set connection type to GPRS
  gprsSerial.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
  delay(2000);
  toSerial();

  // Set the APN
  gprsSerial.println("AT+SAPBR=3,1,\"APN\",\"web\"");
  delay(2000);
  toSerial();

  // Enable GPRS
  gprsSerial.println("AT+SAPBR=1,1");
  delay(10000);
  toSerial();

  // Check to see if connection is correct and get your IP address
  gprsSerial.println("AT+SAPBR=2,1");
  delay(2000);
  toSerial();

}


void loop()
{
   // initialize http service
   gprsSerial.println("AT+HTTPINIT");
   delay(2000); 
   toSerial();

   // set http param value
   // ToDO : send dynamic value
   gprsSerial.println("AT+HTTPPARA=\"URL\",\"http://www.fohoraayo.000webhostapp.com/?lat=1111&lon=1111\"");
   delay(4000);
   toSerial();

   // set http action type 0 = GET, 1 = POST, 2 = HEAD
   gprsSerial.println("AT+HTTPACTION=0");
   delay(6000);
   toSerial();

   // read server response
   gprsSerial.println("AT+HTTPREAD"); 
   delay(1000);
   toSerial();

   //gprsSerial.println("");
   gprsSerial.println("AT+HTTPTERM");
   toSerial();
   delay(300);

   gprsSerial.println("");
   delay(10000);
}

void toSerial()
{
  while(gprsSerial.available()!=0)
  {
    Serial.write(gprsSerial.read());
  }
}

output:

Config SIM900...
Done!...
AT

OK
AT+CPIN?

+CPIN: READY

OK
AT+CREG?

+CREG: 0,1

OK
AT+CGATT?

+CGATT: 1

OK
AT+CSQ 

+CSQ: 31,0

OK
AT+SAPBR=3,1,"Contype","GPRS"

OK
AT+SAPBR=3,1,"APN","web"

OK
AT+SAPBR=1,1

ERROR
AT+SAPBR=2,1

+SAPBR: 1,1,"xx.xxx.x.x"

OK
AT+HTTPINIT

ERROR
AT+HTTPPARA="URL","http://www.fohoraayo.000webhostapp.com/?lat=AT+HTTPACTION=0

ERROR
AT+HTTPREAD

ERROR
AT+HTTPTERM

ERROR
Sushil
  • 31
  • 1
  • 1
  • 2
  • Use this command "AT+CMEE=2\r // Enable +CME ERROR: <err> result code and use verbose <err> values so your module won't response with a simple "ERROR" string but will tell what is the exact problem. Save this parameter with AT&W\r command. –  Nov 08 '16 at 09:22
  • List of possible errors:http://www.micromedia-int.com/en/gsm-2/73-gsm/669-cme-error-gsm-equipment-related-errors with AT+CMEE=2\rthe module should return the error description string. –  Nov 08 '16 at 10:12
  • AT+SAPBR=1,1 this command responds with

    +CME ERROR: operation not allowed and after restarting the gsm module i get ERROR after AT+HTTPINIT

    –  Nov 08 '16 at 10:51
  • When you reset the AT+CMEE=2 setting lost, you have to enable it after every reset or power on or save the setting with AT&W command –  Nov 08 '16 at 10:57
  • What does AT+HTTPINIT returns if you set AT+CMEE=2 before? –  Nov 08 '16 at 14:11
  • It returns ERROR. –  Nov 08 '16 at 16:20
  • http://www.seeedstudio.com/forum/viewtopic.php?p=20195 try this before AT+SAPBR=1,1. –  Nov 08 '16 at 17:30
  • Finally I got it! My sim900 module doesnot supports HTTP. – Sushil Nov 09 '16 at 13:57
  • You can try to use the TCP/IP commands to make a connection and just send a HTTP string along. – aaa Jun 18 '17 at 12:45

1 Answers1

1

For me, your code is working like charm. but change the

gprsSerial.begin(9600)

to

gprsSerial.begin(4800)
Greenonline
  • 2,938
  • 7
  • 32
  • 48