Hi. where is the problem with this sketch ? after 5-30 min nodemcu disconnect from network !
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;
TinyGPSPlus gps; // The TinyGPS++ object
SoftwareSerial ss(RXPin, TXPin); // The serial connection to the GPS device
BlynkTimer timer;
char auth[] = "6075f93a98734b3abddb3c3ba6babf08";
char ssid[] = "MikroTik";
char pass[] = "12345678";
//unsigned int move_index; // moving index, to be used later
unsigned int move_index = 1; // fixed location for now
bool simulation = false; // set to true for simulation mode, else false. If IranHack is true this must be false
// simulation location is in Egypt
bool IranHack = false; // set to true if GPS is faulty, else false. If simulation is true this must be false
WidgetMap myMap(V5);
void setup()
{
Serial.begin(115200);
Serial.println();
ss.begin(GPSBaud);
Blynk.begin(auth, ssid, pass);
timer.setInterval(5000L, checkGPS); // every 5s check if GPS is connected, only really needs to be done once
}
void checkGPS(){
if (gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
Blynk.virtualWrite(V10, "GPS ERROR"); // Value Display widget set as PUSH frequency on V10
Blynk.virtualWrite(V7, "--------"); // Value Display widget set as PUSH frequency on V7 LATITUDE
Blynk.virtualWrite(V8, "--------"); // Value Display widget set as PUSH frequency on V8 LONGITUDE
}
}
void loop()
{
//delay(1000); // NOT RECOMENDED
if(simulation == true || IranHack == true)
{
displayInfo();
}
else
{
while (ss.available() > 0) // sketch displays information every time a new sentence is correctly encoded.
if (gps.encode(ss.read()))
displayInfo();
}
Blynk.run();
timer.run();
}
void displayInfo()
{
if (gps.location.isValid() || simulation == true || IranHack == true)
{
//move_index++; // moving index, maybe use later
Blynk.virtualWrite(V10, "GPS OK");
float latitude = (gps.location.lat()); // removed , 6 as it can't be used for creating the float
float longitude = (gps.location.lng()); // removed , 6 as it can't be used for creating the float
if(latitude == 0 && longitude == 0 ) // checking to see if the 2 floats variables are correct
{
Blynk.virtualWrite(V7, "--------");
Blynk.virtualWrite(V8, "--------");
Blynk.virtualWrite(V10, "0,0");
}
if(simulation == true) // location in Egypt
{
latitude = 30.000123; // also used for debugging
longitude = 30.000987; // also used for debugging
}
if(IranHack == true)
{
latitude = 32.644824;
longitude = 41.681746;
}
Serial.print("LAT: ");
Serial.println(latitude, 6); // float to x decimal places
Serial.print("LONG: ");
Serial.println(longitude, 6);
Blynk.virtualWrite(V7, String(latitude, 6));
Blynk.virtualWrite(V8, String(longitude, 6));
myMap.location(move_index, latitude, longitude, "GPS_Location");
}
else
{
Serial.print(F("INVALID"));
Blynk.virtualWrite(V10, "GPS INVALID");
Blynk.virtualWrite(V7, "--------");
Blynk.virtualWrite(V8, "--------");
}
Serial.println();
}
I suppose that there is too many things on loop function.
Try to use BlynkTimer (AKA SimpleTimer) to launch periodically your check of data and your displayInfo function.
Then keep only Blynk.run() and Timer.run() on loop function.
Thanks for reply. I changed the sketch to below. now its disconnecting and automatically reconnect ! I used simpletimer
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;
TinyGPSPlus gps; // The TinyGPS++ object
SoftwareSerial ss(RXPin, TXPin); // The serial connection to the GPS device
SimpleTimer timer;
char auth[] = "48fcc5ea90e54ce29cc02e6351dc4235";
char ssid[] = "MikroTik Home";
char pass[] = "12345678";
//unsigned int move_index; // moving index, to be used later
unsigned int move_index = 1; // fixed location for now
bool simulation = false; // set to true for simulation mode, else false. If IranHack is true this must be false
// simulation location is in Egypt
bool IranHack = false; // set to true if GPS is faulty, else false. If simulation is true this must be false
WidgetMap myMap(V5);
void setup()
{
Serial.begin(115200);
Serial.println();
ss.begin(GPSBaud);
Blynk.begin(auth, ssid, pass);
timer.setInterval(5000L, checkGPS); // every 5s check if GPS is connected, only really needs to be done once
}
void checkGPS(){
if (gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
Blynk.virtualWrite(V10, "GPS ERROR"); // Value Display widget set as PUSH frequency on V10
Blynk.virtualWrite(V7, "--------"); // Value Display widget set as PUSH frequency on V7 LATITUDE
Blynk.virtualWrite(V8, "--------"); // Value Display widget set as PUSH frequency on V8 LONGITUDE
}
}
void displayInfo()
{
if (gps.location.isValid() || simulation == true || IranHack == true)
{
//move_index++; // moving index, maybe use later
Blynk.virtualWrite(V10, "GPS OK");
float latitude = (gps.location.lat()); // removed , 6 as it can't be used for creating the float
float longitude = (gps.location.lng()); // removed , 6 as it can't be used for creating the float
if(latitude == 0 && longitude == 0 ) // checking to see if the 2 floats variables are correct
{
Blynk.virtualWrite(V7, "--------");
Blynk.virtualWrite(V8, "--------");
Blynk.virtualWrite(V10, "0,0");
}
if(simulation == true) // location in Egypt
{
latitude = 30.000123; // also used for debugging
longitude = 30.000987; // also used for debugging
}
if(IranHack == true)
{
latitude = 32.644824;
longitude = 41.681746;
}
Serial.print("LAT: ");
Serial.println(latitude, 6); // float to x decimal places
Serial.print("LONG: ");
Serial.println(longitude, 6);
Blynk.virtualWrite(V7, String(latitude, 6));
Blynk.virtualWrite(V8, String(longitude, 6));
myMap.location(move_index, latitude, longitude, "GPS_Location");
}
else
{
Serial.print(F("INVALID"));
Blynk.virtualWrite(V10, "GPS INVALID");
Blynk.virtualWrite(V7, "--------");
Blynk.virtualWrite(V8, "--------");
}
Serial.println();
}
void loop()
{
//delay(1000); // NOT RECOMENDED
if(simulation == true || IranHack == true)
{
displayInfo();
}
else
{
while (ss.available() > 0) // sketch displays information every time a new sentence is correctly encoded.
if (gps.encode(ss.read()))
displayInfo();
}
Blynk.run();
timer.run();
}
You still have many things on loop, you didn’t change anything here…
Try to put this on another function and call it every 100ms or so with simpleTimer…
Ok. im adding this code to another func Now it said No GPS detected: check wiring. in the serial monitor
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;
TinyGPSPlus gps; // The TinyGPS++ object
SoftwareSerial ss(RXPin, TXPin); // The serial connection to the GPS device
SimpleTimer timer;
char auth[] = "48fcc5ea90e54ce29cc02e6351dc4235";
char ssid[] = "MikroTik Home";
char pass[] = "12345678";
//unsigned int move_index; // moving index, to be used later
unsigned int move_index = 1; // fixed location for now
bool simulation = false; // set to true for simulation mode, else false. If IranHack is true this must be false
// simulation location is in Egypt
bool IranHack = false; // set to true if GPS is faulty, else false. If simulation is true this must be false
WidgetMap myMap(V5);
void setup()
{
Serial.begin(115200);
Serial.println();
ss.begin(GPSBaud);
Blynk.begin(auth, ssid, pass);
timer.setInterval(5000L, checkGPS); // every 5s check if GPS is connected, only really needs to be done once
}
void checkGPS()
{
if (gps.charsProcessed() < 10)
if(simulation == true || IranHack == true)
{
displayInfo();
}
else
{
while (ss.available() > 0) // sketch displays information every time a new sentence is correctly encoded.
if (gps.encode(ss.read()))
displayInfo();
}
{
Serial.println(F("No GPS detected: check wiring."));
Blynk.virtualWrite(V10, "GPS ERROR"); // Value Display widget set as PUSH frequency on V10
Blynk.virtualWrite(V7, "--------"); // Value Display widget set as PUSH frequency on V7 LATITUDE
Blynk.virtualWrite(V8, "--------"); // Value Display widget set as PUSH frequency on V8 LONGITUDE
}
}
void displayInfo()
{
if (gps.location.isValid() || simulation == true || IranHack == true)
//move_index++; // moving index, maybe use later
Blynk.virtualWrite(V10, "GPS OK");
float latitude = (gps.location.lat()); // removed , 6 as it can't be used for creating the float
float longitude = (gps.location.lng()); // removed , 6 as it can't be used for creating the float
if(latitude == 0 && longitude == 0 ) // checking to see if the 2 floats variables are correct
{
Blynk.virtualWrite(V7, "--------");
Blynk.virtualWrite(V8, "--------");
Blynk.virtualWrite(V10, "0,0");
if(simulation == true) // location in Egypt
{
latitude = 30.000123; // also used for debugging
longitude = 30.000987; // also used for debugging
}
if(IranHack == true)
{
latitude = 32.644824;
longitude = 41.681746;
}
Serial.print("LAT: ");
Serial.println(latitude, 6); // float to x decimal places
Serial.print("LONG: ");
Serial.println(longitude, 6);
Blynk.virtualWrite(V7, String(latitude, 6));
Blynk.virtualWrite(V8, String(longitude, 6));
myMap.location(move_index, latitude, longitude, "GPS_Location");
}
else
{
Serial.print(F("INVALID"));
Blynk.virtualWrite(V10, "GPS INVALID");
Blynk.virtualWrite(V7, "--------");
Blynk.virtualWrite(V8, "--------");
}
Serial.println();
}
void loop()
{
Blynk.run();
timer.run();
}
I guess that it is related to the shield that you are using is too slow, I had similar issues and use a ethernet shield instead the ESP8266 and was solve¡
if the ESP8266 works with AT commands and the workload is high, the systems stucks and take some time to reconect¡
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;
TinyGPSPlus gps; // The TinyGPS++ object
SoftwareSerial ss(RXPin, TXPin); // The serial connection to the GPS device
SimpleTimer timer;
char auth[] = "48fcc5ea90e54ce29cc02e6351dc4235";
char ssid[] = "MikroTik Home";
char pass[] = "12345678";
//unsigned int move_index; // moving index, to be used later
unsigned int move_index = 1; // fixed location for now
bool simulation = false; // set to true for simulation mode, else false. If IranHack is true this must be false
// simulation location is in Egypt
bool IranHack = false; // set to true if GPS is faulty, else false. If simulation is true this must be false
WidgetMap myMap(V5);
void setup()
{
Serial.begin(115200);
Serial.println();
ss.begin(GPSBaud);
Blynk.begin(auth, ssid, pass);
timer.setInterval(5000L, checkGPS); // every 5s check if GPS is connected, only really needs to be done once
timer.setInterval(100L, check);
}
void checkGPS(){
if (gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
Blynk.virtualWrite(V10, "GPS ERROR"); // Value Display widget set as PUSH frequency on V10
Blynk.virtualWrite(V7, "--------"); // Value Display widget set as PUSH frequency on V7 LATITUDE
Blynk.virtualWrite(V8, "--------"); // Value Display widget set as PUSH frequency on V8 LONGITUDE
}
}
void displayInfo()
{
if (gps.location.isValid() || simulation == true || IranHack == true)
{
//move_index++; // moving index, maybe use later
Blynk.virtualWrite(V10, "GPS OK");
float latitude = (gps.location.lat()); // removed , 6 as it can't be used for creating the float
float longitude = (gps.location.lng()); // removed , 6 as it can't be used for creating the float
if(latitude == 0 && longitude == 0 ) // checking to see if the 2 floats variables are correct
{
Blynk.virtualWrite(V7, "--------");
Blynk.virtualWrite(V8, "--------");
Blynk.virtualWrite(V10, "0,0");
}
if(simulation == true) // location in Egypt
{
latitude = 30.000123; // also used for debugging
longitude = 30.000987; // also used for debugging
}
if(IranHack == true)
{
latitude = 32.644824;
longitude = 41.681746;
}
Serial.print("LAT: ");
Serial.println(latitude, 6); // float to x decimal places
Serial.print("LONG: ");
Serial.println(longitude, 6);
Blynk.virtualWrite(V7, String(latitude, 6));
Blynk.virtualWrite(V8, String(longitude, 6));
myMap.location(move_index, latitude, longitude, "GPS_Location");
}
else
{
Serial.print(F("INVALID"));
Blynk.virtualWrite(V10, "GPS INVALID");
Blynk.virtualWrite(V7, "--------");
Blynk.virtualWrite(V8, "--------");
}
Serial.println();
}
void check()
{
if(simulation == true || IranHack == true)
{
displayInfo();
}
else
{
while (ss.available() > 0) // sketch displays information every time a new sentence is correctly encoded.
if (gps.encode(ss.read()))
displayInfo();
}
}
void loop()
{
Blynk.run();
timer.run();
}