How to access GPS when using ThingerTinyGSM

Hello

Using the examples that @alvarolb and @PCAT posted in Connect to thinger.io via GPRS module (done), I have working code which connects to thinger OK, but I would now like to use the GPS function on the SIM7000E that I am using to get the GPS location, but I am unable to get the code to work.

Initially I have created the following function

void enableGPS(void)
{
  Serial.println("START GPS");
  modem.sendAT("+SGPIO=0,4,1,1");
  if (modem.waitResponse(10000L) != 1)
  {
    Serial.println("GPS FAIL");
    //Serial.println("SGPIO=0,4,1,1 false ");
  }
  modem.enableGPS();
}

then called this function in the set-up

  enableGPS();

  float lat, lon;
  while (1)
  {
    if (thing.modem.getGPS(&lat, &lon))
    {
      Serial.print(lat);
      Serial.print(",");
      Serial.println(lon);
    }
    delay(7500);
  }

This is based on some examples that I have found using the TinyGSM library, but it results in the following compile error (when using PlatformIO)

’modem’ was not declared in this scope

Any ideas what I am doing wrong? I think it might be something to do with the ThingerTinyGSM library handling the GSM connection, but I have no idea how to fix this.

Please help.

Thanks

I have figured it out myself, I needed to create the object ‘modem’ in relation to the TinyGSM class

Added this into the header

TinyGsm modem(Serial2);
TinyGsmClient client(modem);

I will tidy up the whole code and post it here

1 Like

I’m using a SIM7000E module, available from Waveshare, and FireBeetle from DFrobot.

Connections

SIM7000E Module <-----> FireBeetle
5V <-----> VCC
GND <-----> GND
RXD <-----> GPIO17
TXD <-----> GPIO16
DTR <-----> NC
PWR <-----> NC

Code

Using PlatformIO. Hope this helps someone. :grinning:

/*****************************************************
** TEST THINGER.IO GPRS CONNECTION           
******************************************************/
//Setup debug & TLS
#define _DISABLE_TLS_ //Required for ESP devices to prevent compile error.
#define _DEBUG_ //Comment out to prevent constant debug OP on serial coms
#define THINGER_SERIAL_DEBUG
//#define THINGER_SERVER "xxxxxxxx" // Only required if host has been set up (xxxx=host name), 
//https://docs.thinger.io/server-configuration/cluster-server-status

//Select your modem:
#define SerialMon Serial
#define TINY_GSM_DEBUG SerialMon //enables debug messages from tinyGSM library
//#define TINY_GSM_MODEM_SIM800 //Note SimCom docs state that SIM7000e used same commands as SIM800
#define TINY_GSM_MODEM_SIM7000 //Note SimCom docs state that SIM7000e used same commands as SIM800

#include <Arduino.h> //required by platformio
#include <string.h> //required for char string manipulation
#include <ThingerESP32.h> //IOT Platform www.thinger.io
#include <TinyGSM.h> //GPRS Library
#include <TinyGSMClient.h> //GPRS Library
#include <ThingerTinyGSM.h> //Thinger GPRS Library

/*************CHANGE LOG******************************
V00.00.00
  •Initial build
*****************************************************
******LIMIT COMMENT LINES TO THIS LENGTH FOR GIT*****
*****************************************************/
String Ver = "V00.00.00"; //Code version

//values for APN
#define APN_NAME "xxxxxxx" //check SIM card provider for APN details
#define APN_USER ""
#define APN_PSWD ""

//Pins for GPRS TxRx
#define RXD1 16 //GPIO16
#define TXD1 17 //GPIO17

//Define thinger.io credentials / settings
#define USERNAME "xxxxxx"    //Thinger Account User Name
#define DEVICE_ID "xxxxxxx"  //Device ID, as set in Thinger.io
#define DEVICE_CREDENTIAL "xxxxxxx"  //Device Credential, as set in Thinger.io
ThingerTinyGSM thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL, Serial2);
TinyGsm modem(Serial2); //Required to allow access to GPS functions within TinyGSM library
TinyGsmClient client(modem); //Required to allow access to GPS functions within TinyGSM library

//Define LED control pins & SYSTEM variables
#define LEDpwr 2 //GPIO2 pin to use for power LED (Built-in)

//Variables for loops & cycle timming
int i = 0;
long msTimer = 0; //used for cycle timing

//GPS variables
float lat, lon;

/***************************************
************** FUNCTIONS ***************
****************************************/

/***************************************
 * GPS Functions *
 ***************************************/
void enableGPS(void)
{
  Serial.println("START GPS");
  modem.sendAT("+SGPIO=0,4,1,1");
  if (modem.waitResponse(10000L) != 1)
  {
    Serial.println("GPS FAIL");
    //Serial.println("SGPIO=0,4,1,1 false ");
  }else{
    Serial.println("GPS ON");
  }
  modem.enableGPS();
}

/***************************************
*********** SET-UP SECTION *************
****************************************/
void setup()
{
//Initialise Serial Coms  
  Serial.begin(115200);  // start serial for output
  Serial2.begin(115200, SERIAL_8N1, RXD1, TXD1); //2nd serial for GPRS module

//Input / Output pin Initialisation
  pinMode(LEDpwr, OUTPUT); //set LED GPIO Pin

//Enable switched LED's & power pin
  digitalWrite(LEDpwr, HIGH); //Turn ON LED

//Output status
  Serial.println(); Serial.println();
  Serial.println("Thinger GPRS Connection Test");
  Serial.print("Device ID - ");
  Serial.println(DEVICE_ID);
  Serial.println();
  delay(1000);

//Delay 5 seconds to wait for GSM to start up
//Flash LED to show
  Serial.println("Wait for GPRS to wake-up");
  for (int i = 0; i < 5; i++) 
    {
      Serial.println(5-i);
      digitalWrite(LEDpwr, LOW); //Turn OFF GREEN LED
      delay(250);
      digitalWrite(LEDpwr, HIGH); //Turn ON GREEN LED
      delay(250);
      digitalWrite(LEDpwr, LOW); //Turn OFF GREEN LED
      delay(250);
      digitalWrite(LEDpwr, HIGH); //Turn ON GREEN LED
      delay(250);
    }

//initialise APN Connection
  thing.setAPN(APN_NAME, APN_USER, APN_PSWD);

//set timer
  msTimer = millis();

//////THINGER VARIABLES//////
//////Device details//////
  thing["DevStatus"] >> [] (pson& out){
    out["device"] = String(DEVICE_ID);
    out["Version"] = Ver;
    out["WakeUpTime(s)"] = millis()/1000;
    out["latitude"] = lat;
    out["longitude"] = lon;
  }; 
}

/******************************************
*********** MAIN LOOP SECTION *************
*******************************************/
void loop()
{
  thing.handle();  

  //heartbeat timer (10 second) output info via serial
  if (millis()-msTimer>=10000)
  {
    msTimer=millis();
    Serial.println("Thinger Connection & GPS Test");
    Serial.println(DEVICE_ID);
    Serial.print(millis());
    Serial.println("ms");
  
  //Connect GPS
  enableGPS();
  if (modem.getGPS(&lat, &lon))
    {
      Serial.print(lat,15);
      Serial.print(",");
      Serial.println(lon,15);
    }else{
      Serial.println("GPS NO SIGNAL");
    }
  }
}

1 Like

Wow so cool!!

I was wondering how to work with thinger io and LTE or NB-IoT, thank you for sharing that it is already possible.

Have you tried the OTA? Is it fast? by GPRS is a little slow.

Thank you for sharing.

OTA works OK over GPRS, but I dont know if its slower as I have only used OTA update via 4G.