Hello,
I am using NEO6Mv2 with SIM900A. As usual I am sending coordinates to my server using HTTP POST. HTTP post is working very well, no problem with it.
Problem is When I use it with SIM900A, it keeps on showing coordinates (that it received for first time) forever in loop().
However if I remove SIM900A code or simply make 84th line as
if(sats > 30)
in order to bypass the SIM900A related code, it works fine I mean it shows change in coordinates as I travel. (GPS cannot connect to 30 satellites at a time so it bypasses)
If you have these 2 modules, please try to use my sketch. In following code, SoftwareSerial ss is for GPS. I am also using TinyGPS library.
How to solve this problem ?
#include <SoftwareSerial.h>
#include <TinyGPS.h>
/* This sample code demonstrates the normal use of a TinyGPS object.
It requires the use of SoftwareSerial, and assumes that you have a
4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/
#define RXPIN 4
#define TXPIN 5
TinyGPS gps;
SoftwareSerial ss(RXPIN, TXPIN);
SoftwareSerial SIM900(2,3);
static void smartdelay(unsigned long ms);
static void print_date(TinyGPS &gps);
static void print_str(const char *str, int len);
String strL, strN, message, textForSMS;
char charL[10], charN[10], text[200];
bool flag;
void setup()
{
SIM900.begin(9600);
ss.begin(9600);
Serial.begin(9600);
ss.listen();
Serial.print("Testing TinyGPS library v. "); Serial.println(TinyGPS::library_version());
Serial.println("by Mikal Hart");
Serial.println();
Serial.println("Sats HDOP Latitude Longitude Fix Date Time Date Alt Course Speed Card Distance Course Card Chars Sentences Checksum");
Serial.println(" (deg) (deg) Age Age (m) --- from GPS ---- ---- to London ---- RX RX Fail");
Serial.println("-------------------------------------------------------------------------------------------------------------------------------------");
delay(2000);
flag = true;
}
void loop()
{
if(flag == false)
{
ss.listen();
delay(2000);
}
int sats,hdops;
float flat, flon;
unsigned long age, date, time, chars = 0, llat, llon;
unsigned short sentences = 0, failed = 0;
//static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;
static const double LONDON_LAT = 19.105466, LONDON_LON = 72.849769;
String message = "";
memset(charL, 0, sizeof(charL));
memset(charN, 0, sizeof(charN));
sats = print_int(gps.satellites(), TinyGPS::GPS_INVALID_SATELLITES, 5);
hdops = print_int(gps.hdop(), TinyGPS::GPS_INVALID_HDOP, 5);
gps.f_get_position(&flat, &flon, &age);
dtostrf(flat, 4, 6, charL);
dtostrf(flon, 4, 6, charN);
Serial.print(charL);
Serial.print(" ");
Serial.print(charN);
message = "lat=";
message += charL;
message += "&lon=";
message += charN;
Serial.print(" ");
Serial.println(message);
Serial.println();
Serial.print("Connected Sats ::: ");
Serial.println(sats);
Serial.println();
if(sats > 0)
{
Serial.println(message);
Serial.println();
SIM900INIT(message);
SIM900STOP();
smartdelay(1000);
}
smartdelay(1000);
flag = false;
}
static void smartdelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (ss.available())
gps.encode(ss.read());
} while (millis() - start < ms);
}
float print_float(float val, float invalid, int len, int prec)
{
if (val == invalid)
{
while (len-- > 1)
Serial.print('*');
Serial.print(' ');
}
else
{
Serial.print(val, prec);
int vi = abs((int)val);
int flen = prec + (val < 0.0 ? 2 : 1); // . and -
flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
for (int i=flen; i<len; ++i)
Serial.print(' ');
}
smartdelay(0);
}
int print_int(unsigned long val, unsigned long invalid, int len)
{
char sz[32];int returner;
if (val == invalid)
strcpy(sz, "*******");
else
sprintf(sz, "%ld", val);
sz[len] = 0;
for (int i=strlen(sz); i<len; ++i)
sz[i] = ' ';
if (len > 0)
sz[len-1] = ' ';
returner = atoi(sz);
return returner;
}
static void print_date(TinyGPS &gps)
{
int year;
byte month, day, hour, minute, second, hundredths;
unsigned long age;
gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
if (age == TinyGPS::GPS_INVALID_AGE)
Serial.print("********** ******** ");
else
{
char sz[32];
sprintf(sz, "%02d/%02d/%02d %02d:%02d:%02d ",
month, day, year, hour, minute, second);
Serial.print(sz);
}
print_int(age, TinyGPS::GPS_INVALID_AGE, 5);
smartdelay(0);
}
static void print_str(const char *str, int len)
{
int slen = strlen(str);
for (int i=0; i<len; ++i)
Serial.print(i<slen ? str[i] : ' ');
smartdelay(0);
}
void SIM900INIT(String msg)
{
SIM900.listen();
String httpdata = "";
SIM900.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
delay(1000);
SIM900.println("AT+SAPBR=3,1,\"APN\",\"bsnlnet\"");
delay(1000);
SIM900.println("AT+SAPBR=1,1");
delay(3500);
SIM900.println("AT+SAPBR=2,1");
delay(3500);
SIM900.println("AT+HTTPTERM");
delay(1000);
SIM900.println("AT+HTTPINIT");
delay(1000);
SIM900.println("AT+HTTPPARA=\"CID\",1");
delay(1000);
SIM900.println("AT+HTTPPARA=\"URL\",\"hxxp://hostname.tld/record\"");
delay(1000);
SIM900.println("AT+HTTPPARA=\"CONTENT\",\"application/x-www-form-urlencoded\"");
delay(1000);
httpdata = "AT+HTTPDATA=";
httpdata += msg.length();
httpdata += ",2000";
Serial.println(SIM900.println(httpdata));
delay(1000);
Serial.println(SIM900.println(msg));
delay(1000);
Serial.println(SIM900.println("AT+HTTPACTION=1"));
delay(5000);
}
void SIM900STOP()
{
SIM900.println("AT+HTTPTERM");
delay(1000);
}
void ShowSerialData()
{
while(SIM900.available()!=0)
Serial.write(SIM900.read());
}
I am really puzzled with this problem.