I have a GPS Tracker project wich causes me problem. All seems to work and Blynk connects. But after a moment it disconnect and goes offline. Even if I use a 18650 battery or a lab generator.
I use an ESP32 + SIM800L + NEO6M
Here is my code, if you find something wrong.
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPLS6-Qv61A"
#define BLYNK_DEVICE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "xxx"
// Select your modem:
#define TINY_GSM_MODEM_SIM800
//#define TINY_GSM_MODEM_SIM900
//#define TINY_GSM_MODEM_M590
//#define TINY_GSM_MODEM_A6
//#define TINY_GSM_MODEM_A7
//#define TINY_GSM_MODEM_BG96
//#define TINY_GSM_MODEM_XBEE
// Default heartbeat interval for GSM is 60
// If you want override this value, uncomment and set this option:
//#define BLYNK_HEARTBEAT 15
#include <TinyGPS++.h> //https://github.com/mikalhart/TinyGPSPlus
#include <TinyGsmClient.h> //https://github.com/vshymanskyy/TinyGSM
#include <BlynkSimpleTinyGSM.h> //https://github.com/blynkkk/blynk-library
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxx";
// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[] = "iot.1nce.net";
//char apn[] = "symamobile.com";
//char apn[] = "free";
char user[] = "";
char pass[] = "";
//sender phone number with country code.
//not gsm module phone number
//const String PHONE = "Enter_Your_Phone_Number";
//GSM Module Settings
//GSM Module RX pin to ESP32 2
//GSM Module TX pin to ESP32 4
#define rxPin 16
#define txPin 17
HardwareSerial sim800(1);
TinyGsm modem(sim800);
//GPS Module Settings
//GPS Module RX pin to ESP32 17
//GPS Module TX pin to ESP32 16
#define RXD2 3
#define TXD2 1
HardwareSerial neogps(2);
TinyGPSPlus gps;
BlynkTimer timer;
void setup() {
//Set Serial monitor baud rate
Serial.begin(115200);
Serial.println("esp32 serial initialize");
delay(10);
//Set GSM module baud rate
sim800.begin(9600, SERIAL_8N1, rxPin, txPin);
Serial.println("SIM800L serial initialize");
delay(3000);
//Set GPS module baud rate
neogps.begin(9600, SERIAL_8N1, RXD2, TXD2);
Serial.println("neogps serial initialize");
delay(10);
// Restart takes quite some time
// To skip it, call init() instead of restart()
Serial.println("Initializing modem...");
modem.restart();
// Unlock your SIM card with a PIN
//modem.simUnlock("1234");
Blynk.begin(auth, modem, apn, user, pass);
timer.setInterval(5000L, sendToBlynk);
}
void loop() {
while(neogps.available())
{
if (gps.encode(neogps.read()))
{
sendToBlynk();
}
}
Blynk.run();
timer.run();
} //main loop ends
void sendToBlynk()
{
if (gps.location.isValid() )
{
//get latitude and longitude
double latitude = gps.location.lat();
double longitude = gps.location.lng();
//get speed
float speed = gps.speed.kmph();
//get number of satellites
float satellites = gps.satellites.value();
//get altitude
float altitude = gps.altitude.meters();
Blynk.virtualWrite(V0, longitude, latitude);
Blynk.virtualWrite(V1, String(latitude, 6));
Blynk.virtualWrite(V2, String(longitude, 6));
Blynk.virtualWrite(V3, speed);
Blynk.virtualWrite(V4, satellites);
Blynk.virtualWrite(V5, altitude);
}
}
Thanks in advance for your futures answers.
Franck
I specify that my project don’t move from start until it goes offline and I always have network with my SIM card and the NEO6M is still picking up the sattelites
Hi Pete and thanks for your answer.
I think I don’t understand too much but I tried to comment all the lines with Serial.println and the problem is still there.
This time the connection goes online and offline multiple times to stay offline after 3-4 times
It’s not simply a case of deleting all the other code from your void loop, you need to read the “keep your void loop clean” document and understand it, then make the appropriate changes.
What I understood with the “keep your void loop clean” is that if I have a timer I must to relate it with a function. Mine is sendToBlynk
In this function I have my GPS Code then every 5 seconds my timer send to the sendToBlynk function.
Am I right?
Sorry, I try to make it as simple as possible because english is not my mother tongue, I’m French. I try to make my best to make me understand
The debug serial output is a little problem either… indeed, when I transfer the code to the ESP I have nothing showing in the serial monitor. But when I press the reset button on the ESP I have a little bit of information but not enough to debug.
In fact, after “entry 0x400806a8” I should have the informations about modem init etc. but I have nothing of that and I don’t now why. I missed something certainly…
Okay, so you have a non-Blynk related issue that you need to resolve first.
This may be associated with your ESP_32 Core version, the upload settings (DIO for example) that you’ve chosen, the board type that you’ve chosen etc etc.
You need to fix these issues first before you can hope to get connected to Blynk.