{GPS MODULE + ARDUINO + Esp8266} Push sensor code running only for 10 seconds. Need help with Blynk timer

@Abhinav_Thakur If we give you the code you will learn nothing.

I tried a lot with Blynk timer but it is unable to read from the module. But, still this code is able to run for 10 seconds without Blynk timer. Can someone plz help.

#include <SoftwareSerial.h>
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>


static const int RXPin = 8, TXPin = 9;   
static const uint32_t GPSBaud = 9600; 

TinyGPSPlus gps; 

SoftwareSerial ss(RXPin, TXPin);  

char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";             
char ssid[] = "abhi";                                      
char pass[] = "12345678abhinav";                                      


#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); 


#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

BlynkTimer timer; 

  
unsigned int move_index = 1;         





void setup()
{
  Serial.begin(9600); 
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  Blynk.begin(auth, wifi, ssid, pass);
  ss.begin(GPSBaud);
  timer.setInterval(1000L, myTimerEvent);
}


void displaypd()
{
    if (gps.location.isValid())
  {
    Serial.print(F("Latitude: "));
    Serial.print(gps.location.lat(), 6);
    Serial.print(F("  Longitude: "));
    Serial.println(gps.location.lng(), 6);
  }  
    
}


void myTimerEvent()
{
   while(ss.available() > 0)
    {
      if (gps.encode(ss.read()))
        displaypd();
      
       }
}




void loop()
{
  Blynk.run();
  timer.run(); 
}

As I have already stated… there is a Blynk heartbeat of about 10 seconds… in which your code can sit there and work, not work, twiddle it’s itty bity bytes or flat out do notheng… but if if after those 10 seconds, Blynk can not get on with it’s required housekeeping, then your wholes sketch stops.

So please stop using the blocking while() loop and focus on learning how to use timers instead of while() to get the job done :wink:

Dude as you told me to change the while loop i tried to modify by using if loop. On using it without Blynk it gives the right response but when i use it with Blynk, it gives nothing.
I am not even getting output for 10 seconds as i was getting using while statement using Blynk. Can you please tell where i am wrong.

void loop()
{
  Blynk.run();
 if (ss.available() )
    {
      if (gps.encode(ss.read()))
      {  if (gps.location.isValid())
  {
    Serial.print(F("Latitude: "));
    Serial.print(gps.location.lat(), 6);
    Serial.print(F("  Longitude: "));
    Serial.println(gps.location.lng(), 6);
  }  
    } }
  
}

I also suggested using timers… so that you are not flooding or overloading your void loop() with scanning every few hundredths of a second. :wink:

Put everything you currently have, but the Blynk.run(); in a timed function and start testing how best to make it work with Blynk that way.

Aside from these suggestions… no, not really… you just need to slowly learn how Blynk works, that is all.

No magic bullet answers are otherwise available.

I studied about interrupts and timers and about blynk timer. I never used Simple timer before so i am new to it. Can you please tell if my timer code is technically correct. Secondly, can you please tell me where i should use which time interval. I am not clear about that .

And what does it really mean in GPS problem. Does this has anything to do with my problem:

Plz dude help. I am a noob :yum:

I don’t have any of those GPS devices to test, but probably something like this in a timed loop…

In your case, set for every 1000ms (1 second) or whatever works best for you.

timer.setInterval(1000L, myTimerEvent);  // This goes in the void setup() and runs the function every 1 second
void myTimerEvent()
{
  if (gps.encode(ss.read()))  // I don't know why you need an if condition here?
  {
    if (gps.location.isValid())
    {
      Serial.print(F("Latitude: "));
      Serial.print(gps.location.lat(), 6);
      Serial.print(F("  Longitude: "));
      Serial.println(gps.location.lng(), 6);
    }
  }
}

It will not work without

As it is used to repeatedly feed characters from your GPS device.

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

I am unable to find any gps codes linked to Blynk. Bro, i have very less time left to finish my project so plz i need to solve it quick. Btw, thanks for all ur help.

Blynk is a IoT GUI interface… so it has uses in multiple fields, not just GPS, of which there are many, many differing ways to process that data… but the particular method you seem to need might be a little too demanding in it’s own timing needs.

I suppose you could try to reintroduce the while() but add in another Blynk.run(); command after every data dump (e.g. coordinate printout and Blynk.virtualWrite() - if used) as that will allow Blynk to keep up with it’s own timing needs for housekeeping and communication.

Then tweak your timer until you get a smooth data flow without causing flooding from too much data flow to the App or disconnections from not enough Blynk housekeeping.

As I said, I have nothing to test or compare with (and my own projects to work on), so while I can throw out a few ideas, you need to keep reading and trying things on your own as well… a lot of the flooding and disconnection reasons and solutions have already been documented and discussed in this forum.

@Costas can u plz help me out here. I read an answer written by u on gps.

Btw, Gunner i will try to do what u just said

Study the following thread [SOLVED] Arduino or NodeMCU GPS tracking system on Map widget

@costas i read the article. Unable to run with my setup. I have error in ESP.wdtFeed(); Maybe its because i am using a {arduino + esp8266} and not esp8266 shield.

Can you please provide me with the final fixed code you got. Its very urgent. Ineed to finish soon. I tried everything but nothing is working. :disappointed_relieved:

It’s specific to ESP and shouldn’t really be needed with an Arduino.

I have enough of my own deadlines without worrying about yours.

Nothing is being printed on the screen. Btw @Costas don’t be angry. I am trying since past five days and nothing productive is coming out. :sob:

[11036] Connected to WiFi
[21892] Ready (ping: 25ms).
[31944] Login timeout
[52742] Ready (ping: 23ms).
[62794] Login timeout
[78220] Ready (ping: 24ms).
[88272] Login timeout

@Abhinav_Thakur don’t mess up the site with duplicate posts.

Have you actually tested your Arduino + ESP with anything simpler than GPS?

I happen to know that you use ISP’s that are quite different to what most Blynkers use. It could be something as simple as that. If you haven’t already tested the basic Blynk examples forget GPS and work through them with as much Serial Monitor data as you can get.

Don’t forget that Arduino’s weren’t designed to work with ESP’s and you will get much better results using ESP’s in standalone mode.

@Costas i’m new to this platform but i did try some things before. Btw i am unable to do it on blynk that’s why i am asking for help. This platform is different and there are not much examples to look into.

There is a huge list of examples and I suggest you start with blinking an LED like the rest of did when we first found Blynk.

Dude dont try to mock me but i have done those things before. I am asking for help.Plus i have wasted too much time here. If you can, its cool and if you don’t then plz don’t

I’m not mocking anyone I’m simply telling you how to get the most out of Blynk.

Sorry I couldn’t help you.