Sim800 gprs connection


#1

Hello there below is the code I wrote to transmit sensor stays and location and transmits through sim800 sometimes the sim800 transmits and sometimes it does not
Sim800.println(“AT+CGATT=1\r\n”);
delay(100);
toSerial();

// bearer settings
Sim800.println(“AT+SAPBR=3,1,“CONTYPE”,“GPRS””);
delay(2000);
toSerial();

// bearer settings
Sim800.println(“AT+SAPBR=3,1,“APN”,“web.gprs.mtnnigeria.net””);
delay(2000);
toSerial();

// bearer settings
Sim800.println(“AT+SAPBR=1,1”);
delay(2000);
toSerial();
Sim800.println(“AT+SAPBR=2,1”);
delay(2000);
toSerial();
// initialize http service
Sim800.println(“AT+HTTPINIT”);
delay(2000);
toSerial();
Sim800.println(“AT+HTTPPARA=CID,1”);
delay(2000);
toSerial();
// set http param value
Sim800.println("AT+HTTPPARA=“URL”,“https://weatherdetector.ng/dht11/v1/activate.php?sensor_code=ng&status=0"”); // Send PARA command
delay(2000);
toSerial();

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

// read server response
Sim800.println(“AT+HTTPREAD”);
delay(5000);
toSerial();
Sim800.println("");
Sim800.println(“AT+HTTPTERM”);
toSerial();
delay(1000);
Sim800.println("");


#2

Putting delay after every command is not the right way to do it. You need to handle the responses. Read command responses and take appropriate action. Or the code will flow blindly and it keeps sending next command even though previous command failed. Look at Libelium libararies they have good examples for AT command handling in their libraries for GSM modules.