Hey,
So i've got SIM800 working fine with AT-commands.
At the moment my code is working with delays. I've basically just tested how many seconds does it take for the GSM to get online and send the data.
I would like some help on how to IF's for the procedure. For example, to check if the module is online and only then proceed. Perhaps if it fails multiple times -> do something.
void sendData() {
Serial.println("Starting data transfer");
int u;
for (u = 0; u < 20; u++) {
delay(500);
Serial.print(".");
}
Serial.println(""); // print empty line
delay(3000);
Serial.println("Sending data");
delay(100);
serialSIM800.println("AT+SAPBR=3,1,\"APN\",\"internet\"");
delay(1000);
serialSIM800.println("AT+SAPBR=1,1");
delay(1000);
serialSIM800.println("AT+HTTPINIT");
delay(500);
serialSIM800.println("AT+HTTPPARA=\"CID\",1");
delay(500);
serialSIM800.println("AT+HTTPPARA=\"UA\",\"Paatti_0_8\""); // Change User Agent for web server
delay(500);
Serial.println("Starting payload");
char valA[10], valB[10], valC[10], valD[10], valE[10], valF[10];
String identifier = String("Testip");
String location = String("lokaatio");
//dtostrf(identifier, 20,20, valA); // identifier A
//dtostrf(location, 3, 3, valB); // location B
dtostrf(vin, 3, 2, valC); // voltage C
dtostrf(acsCurrent, 4, 3, valD); // current D
dtostrf(t, 3, 2, valE); // temp E
dtostrf(h, 3, 2, valF); // humi F
char urlData[200];
/* Order of URL
identifier
location
voltage
current
temp
humi
gps_lat
gps_long
*/
// Construct Payload for URL
strcpy(urlData, "\"AT+HTTPPARA=\"URL\",\"http://url.domain.fi/simlogger/db_simlogger_insert.php?");
strcat(urlData, "pw=");
strcat(urlData, "13fev"); // Secret password
strcat(urlData, "&identifier=");
strcat(urlData, "ident"); // change to variable
strcat(urlData, "&location=");
strcat(urlData, "loc"); // change to variable
strcat(urlData, "&voltage=");
strcat(urlData, valC);
strcat(urlData, "¤t=");
strcat(urlData, valD);
strcat(urlData, "&temp=");
strcat(urlData, valE);
strcat(urlData, "&humi=");
strcat(urlData, valF);
strcat(urlData, "&gps_lat=");
strcat(urlData, "10.000000"); // change to variable
strcat(urlData, "&gps_long=");
strcat(urlData, "20.000000"); // change to variable
strcat(urlData, "\"");
Serial.print("Payload: "); //
Serial.print(urlData); // Print to serial console to see what is inside the payload
Serial.println(" EOL"); //
delay(3000); // Important (datalenght)
Serial.println("Payload ready, send to modem");
serialSIM800.println(urlData); // Print to modem
delay(3000); // Important (datalenght)
serialSIM800.println("AT+HTTPACTION=0");
Serial.println("Data sent!");
delay(4000);
}