Go Down

Topic: Gprs SIM900 and Gps NEO-6M don't work together (Read 5652 times) previous topic - next topic

robsonfagundes

I'm trying to get gps position and send to my API through the shields Gprs SIM900 and Gps NEO-6M.

On setup(), first I start gprs shield and call the function that connects to internet. Then on loop(), I start to capture gps position and finally I sending to api, but my code don't work with this logic. I'd like connects once and get gps coordinates and send to api many times making a tracking.

The app stops if I run the code. connectToInternet() on setup() and getGpsPosition() loop(). The shield SIM900 connects but the shield NEO6-M does not display the coordinates. The GPS only capture the coordinates if I do not connect to internet.

Could someone help me? Following is my code and print of the response AT commands. 

Code: [Select]

#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#include <inetGSM.h>

static const int RXPin = 4, TXPin = 3;

InetGSM inet;
TinyGPSPlus gps;
SoftwareSerial serialGps(RXPin, TXPin);

char msg[50];
boolean started = false;
const char* dataCoord = "";

/**
setup
*/
void setup() {
// Serial connection.
Serial.begin(19200);

Serial.print(F("------------------------------------------------- \r\n"));
Serial.println(F("Starting App Tracking Arduino"));
Serial.print(F("------------------------------------------------- \r\n"));

// Turn on GPRS
powerUpGprs();
// Start configuration of shield SIM900 with baudrate.
if (gsm.begin(2400)) {
Serial.println(F("\nstatus=READY"));
started = true;
}
else Serial.println(F("\nstatus=IDLE"));

if (started)
connectToInternet();

// Start configuration of shield GPS NEO-6M with baudrate.
serialGps.begin(9600);
}

/**
loop
*/
void loop() {
// This sketch displays information every time a new sentence is correctly encoded.
while (serialGps.available() > 0)
if (gps.encode(serialGps.read()))
  getGpsPosition();

}

/**
Power up
*/
void powerUpGprs() {
pinMode(9, OUTPUT);
delay(100);
digitalWrite(9, HIGH);
Serial.println(F("\nPower Up SIM900!"));
}

/**
Connect to Internet via GSM
*/
void connectToInternet() {
Serial.print(F("\r\n"));
Serial.print(F("------------------------------------------------- \r\n"));
Serial.print(F(" CONNECT TO INTERNET \r\n"));
Serial.print(F("------------------------------------------------- \r\n"));

//GPRS attach, put in order APN, username and password.
if (inet.attachGPRS("zap.vivo.com.br", "vivo", "vivo"))
Serial.println(F("status=ATTACHED"));
else
Serial.println(F("status=ERROR"));
delay(1000);
//Read IP address.
gsm.SimpleWriteln("AT+CIFSR");
}


/**
Get GPS position
*/
void getGpsPosition() {

Serial.print(F("\r\n\r\n"));
Serial.print(F("------------------------------------------------- \r\n"));
Serial.print(F(" GET POSITON \r\n"));
Serial.print(F("------------------------------------------------- \r\n"));
// geolocation
TinyGPSDate &d = gps.date;
TinyGPSTime &t = gps.time;
char* timestamp;
if (!d.isValid()) {
timestamp = "00/00/0000 00:00:00";
}  else  {
char sz[32];
sprintf(sz, "%02d/%02d/%02d %02d:%02d:%02d",
        d.day(), d.month(), d.year(),
        t.hour(), t.minute(), t.second());
timestamp = sz;
}
String position = String("");
position.concat(String("timestamp=") + String(timestamp));
position.concat(String("&latitude=") + String(gps.location.lat(), 6));
position.concat(String("&longitude=") + String(gps.location.lng(), 6));
position.concat(String("&altitude=") + String(gps.altitude.meters()));
position.concat(String("&speed=") + String(gps.speed.kmph()));
Serial.println(dataCoord);
send2Api();
}

/**
Send To API, The function inet.httpPOST(),
this is submit method POST via http request
*/
void send2Api() {
Serial.print(F("\r\n\r\n"));
Serial.print(F("------------------------------------------------- \r\n"));
Serial.print(F(" SEND TO API\r\n"));
Serial.print(F("------------------------------------------------- \r\n"));

// Read until serial buffer is emapty.
gsm.WhileSimpleRead();

// TCP Client HTTP, send a POST request to the server and save the reply.
int numdata = inet.httpPOST("api.myapp.com.br", 80, "/geolocations ", dataCoord, msg, 100);

// Print the results.
Serial.print(F("\nNumber of data received: "));
Serial.println(numdata);
Serial.print(F("\nData received: "));
Serial.println(msg);
};


If I connect to internet the GPS does not display the coordinates


But, if I don't connect to internet the GPS display the coordinates.

dannable

Which pins are you using to communicate with the SIM900?
Beginners guide to using the Seeedstudio SIM900 GPRS/GSM Shield

dannable

Beginners guide to using the Seeedstudio SIM900 GPRS/GSM Shield

robsonfagundes

#3
Mar 02, 2017, 08:05 pm Last Edit: Mar 02, 2017, 08:14 pm by robsonfagundes Reason: no link url
I solved.... https://github.com/robsonfagundes/Arduino-GprsSIM900andGpsNEO-6M
This example also serves to help other developers who are facing the same problem or a similar problem with Gprs SIM900 and Gps NEO-6M working together.

tiagohigino

Hi!
I saw that you solved your problem and posted a guide on GitHub. How do I send the coordinates to a mobile phone by text message? How do I make the electrical connections? I need to use the connections with Jumpers, without connecting a SIM900 card directly to Uno. Could you please help me with this?

Nivashini

Is that possible to set a specific range to that GPS Neo-6M and make the GSM sim900 to send message when someone crosses that range?

Go Up