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.
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.
/*****************************************************
** 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");
}
}
}