Help me with gps position

Hello all) I’m trying to get gps position data. I have ESP8266 with A7 gps/GPRS module connected. How can I manage gps data with Tintgps++ library. I do everything according to manual but in bucket I have zero instead latitude and longitude.

Bucket:


2017-12-10T11:11:20.446	0.0	0.0
2017-12-10T11:12:23.483	0.0	0.0
2017-12-10T11:13:26.463	0.0	0.0
2017-12-10T11:14:29.504	0.0	0.0
2017-12-10T11:15:32.506	0.0	0.0
2017-12-10T11:16:35.486	0.0	0.0
2017-12-10T11:45:01.620	0.0	0.0
2017-12-10T11:46:39.624	0.0	0.0
2017-12-10T11:54:38.565	0.0	0.0
2017-12-10T12:22:24.981	0.0	0.0

Here is my code:


#define TINY_GSM_MODEM_A7
#define _DEBUG_
#include <TinyGPS++.h>
#include <TinyGsmClient.h>
#include <ThingerTinyGSM.h>
TinyGPSPlus gps;
#include "SoftwareSerial.h"
SoftwareSerial SerialAT(5, 4); // RX, TX
SoftwareSerial ss(14, 12);
#include <SimpleTimer.h>
SimpleTimer timer;
float GPSlat;
float GPSlng;
#define USERNAME "*******"
#define DEVICE_ID "***"
#define DEVICE_CREDENTIAL "*********"

#define APN_NAME "internet.mts.ru"
#define APN_USER "mts"
#define APN_PSWD "mts"

#define CARD_PIN ""

ThingerTinyGSM thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL, SerialAT);

static void smartDelay(unsigned long ms)
{
  unsigned long start = millis();
  do
  { while (ss.available())
      gps.encode(ss.read());
  } while (millis() - start < ms);
}

void setup() {

  Serial.begin(9600);
  delay(500);

  SerialAT.begin(9600);
  delay(1000);
  ss.begin(9600);
  delay(1000);

  SerialAT.println("AT+GPS=1");
  delay(2000);
  // set APN (you can remove user and password from call if your apn does not require them)
  thing.setAPN(APN_NAME, APN_USER, APN_PSWD);


  thing["location"] >> [](pson & out) {

    out["lat"] = GPSlat;
    out["lon"] = GPSlng;
  };
}

void loop() {
  smartDelay(500);
  thing.handle();
  float GPSlat = (gps.location.lat());
  float GPSlng = (gps.location.lng());
}

hello @Akalchuk,

just define GPSlat and GPSlng like global variables, do not re-define them in the loop. :wink:

It’s defened in the beginning of my sketch. But in the loop it’s redefined. I’ll try to do it

No. It won’t work anyway (((
I checked all my connections and serial ports. It work perfect without connect to thinger

I guess you can’t use the serial port because you have connected the GPS on it, so it’s not possible to make serial.prints… isn’t it?

it is preferable not to use lock delays in the loop, so try with something like this:

int lastRead=0;
void loop() {
  if(millis()>lastRead+500){
     GPSlat =(float)gps.location.lat();
     GPSlng =(float)gps.location.lng();
     lastRead=millis();
  }
thing.handle();
}

I have two serial ports. SerialAT connected to modem pin.
And ss connected to VK16e gps module.
Ps. I try new hardware config with same sketch.

And for TinyGPS+++ library need to perform in the loop().
while (ss.available() > 0)
gps.encode(ss.read());

http://arduiniana.org/libraries/tinygpsplus/

fine, so first print the values to be sure that it is working fine

With that code:

#define TINY_GSM_MODEM_A7
#define _DEBUG_
#include <TinyGPS++.h>
#include <TinyGsmClient.h>
#include <ThingerTinyGSM.h>
TinyGPSPlus gps;
#include "SoftwareSerial.h"
SoftwareSerial SerialAT(5, 4); // RX, TX
SoftwareSerial ss(14, 12);
#include <SimpleTimer.h>
SimpleTimer timer;
//float GPSlat;
//float GPSlng;


#define USERNAME "Akalchuk"
#define DEVICE_ID "Gps"
#define DEVICE_CREDENTIAL "123456"

#define APN_NAME "internet.mts.ru"
#define APN_USER ""
#define APN_PSWD ""

#define CARD_PIN ""

//ThingerTinyGSM thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL, SerialAT);

void checkgps(){
  
       if (gps.location.isValid() ) 
  {
    
    float latitude = (gps.location.lat());     //Storing the Lat. and Lon. 
    float longitude = (gps.location.lng()); 
    Serial.print("LAT:  ");
    Serial.println(latitude, 6);  // float to x decimal places
    Serial.print("LONG: ");
    Serial.println(longitude, 6);
   
  }
  Serial.println();
   
  }
    


void setup() {

  Serial.begin(9600);
  delay(500);

  SerialAT.begin(9600);
  delay(1000);
  ss.begin(9600);
  delay(1000);

  
 // thing.setAPN(APN_NAME, APN_USER, APN_PSWD);


 // thing["location"] >> [](pson & out) {
//
   // out["lat"] = GPSlat;
   // out["lon"] = GPSlng;
  //};

  // timer.setInterval(3000, checkgps);
}

void loop() {
  //timer.run();

  while (ss.available() > 0) 
    {
      // sketch displays information every time a new sentence is correctly encoded.
      if (gps.encode(ss.read()))
     
       checkgps();
  }
  //smartDelay(500);
  //if (ss.available()){
   // gps.encode(ss.read());
   // GPSlat = (float)gps.location.lat();
   // GPSlng = (float)gps.location.lng();
  //}

 // thing.handle();
 
 
}

I have commented all for test.

Here is the output:

LAT:  48.426994
LONG: 42.773033

And it doesn’t works? I Still thinking that is all right, but try to include the prints into the thinger resource to be sure that the variables are actualized in this domain, like this:

thing["location"] >> [](pson & out) {

    out["lat"] = GPSlat;
    out["lon"] = GPSlng;
    Serial.print("LAT:  ");
    Serial.println(GPSlat, 6);  // float to x decimal places
    Serial.print("LONG: ");
    Serial.println(GPSlng, 6);
  };

I think I have encounted with two software serial port parallel working problem.
Due to software problem with software serial and ESP8266 it was unable to receive data from gps module, when modem was connected to thinger.

But I changed configuration: now I’m im using Arduino Leonardo + VK16e.
And it’s worked perfect))))
Thank you!!!

Now I have another problem. Time to time in console I get message like that: “ Auth failed! Check username, …” and reconnecting or stop working.
What does it mean? Why?
I’m using 2Amps power supply.