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
"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 withAT&W\r
command. – Bence Kaulics Nov 8 '16 at 9:22AT+CMEE=2\r
the module should return the error description string. – Bence Kaulics Nov 8 '16 at 10:12AT+SAPBR=1,1
this command responds with+CME ERROR: operation not allowed
and after restarting the gsm module i getERROR
afterAT+HTTPINIT
– Sushil Nov 8 '16 at 10:51AT+CMEE=2
setting lost, you have to enable it after every reset or power on or save the setting withAT&W
command – Bence Kaulics Nov 8 '16 at 10:57AT+HTTPINIT
returns if you setAT+CMEE=2
before? – Bence Kaulics Nov 8 '16 at 14:11