I´m using an Arduino Mega 2560 with the SIM808 module. I want to send a HTTP Request with my current GPS coordinates. Viewed separately (in two sketches) I can use both functions. If I combine both sketches the module does not receive GPS data anymore.
Which changes are necessary, so that both function can work together?
#include DFRobot_SIM808 sim808(&Serial);
char buffer[512];
void setup(){
Serial.begin(9600);
//******** Initialize sim808 module *************
while(!sim808.init()) {
delay(1000);
Serial.print("Sim808 init error\r\n");
}
delay(3000);
//*********** Attempt DHCP *******************
while(!sim808.join(F("internet.eplus.de"))) {
Serial.println("Sim808 join network error");
delay(2000);
}
//************ Successful DHCP ****************
Serial.print("IP Address is ");
Serial.println(sim808.getIPAddress());
//************* Turn on the GPS power************
if( sim808.attachGPS())
Serial.println("Open the GPS power success");
else
Serial.println("Open the GPS power failure");
delay(2000);
}
void loop(){
tcp();
delay(2000);
}
void tcp()
{
// Update the GPS data
float lati, longi;
if (sim808.getGPS()) {
lati = sim808.GPSdata.lat;
longi = sim808.GPSdata.lon;
sim808.detachGPS();
}
else {
// No gps, abort
return;
}
//*********** Establish a TCP connection ************
if (!sim808.connect(TCP,"100.100.100.100", 80)) {
Serial.println("Connect error");
return;
}
else {
Serial.println("Connect POPO success");
}
//*********** Send a GET request *****************
char http_cmd[100];
sprintf(http_cmd, "GET /api/v1/Status?latitude=%f&longitude=%f HTTP/1.0\r\n\r\n\0", lati, longi);
sim808.send(http_cmd, strlen(http_cmd));
//************* Close TCP or UDP connections **********
sim808.close();
//*** Disconnect wireless connection, Close Moving Scene *******
sim808.disconnect();
}