I am using Esp8266 wifi module and Arduino. The setup is giving out never ending NMEA output without connecting to Blynk.
But while working with Blynk app i am getting only a single output and its not working after that . The location is accurate as well as there is no problem with the GPS code .
I would suspect that since you are running your GPS reading function directly from the main loop (which runs hundreds of times a second) then you are simply getting flooding errors and disconnections… Blynk needs to be able to constantly function in the background… maintaining a link to the Server and reading/writing data to the Server as required.
Look into running this from a timer instead
while (ss.available() > 0)
{
if (gps.encode(ss.read()))
displayInfo();
}
Actually, try to avoid the while() function all together, as it will lock you into that ‘loop’ while the condition is met… and thus… yep… disconnections
As a result, i am getting output only for 10 seconds every time. Can you please suggest any alternative other than while which i can use as its getting disconnected exactly after 10 seconds. Btw thank you for ur help .
That is because there is a 10 second heartbeat check with Blynk… and since you are probably stuck in your while() loop, Blynk is not able to run in the background.
Check out the BlynkTimer link and read up on the reasons it is needed as already posted above.
Thank you for the link you provided but still i am having the same problem. I have reduced the earlier code. Can you please please add blynk timer to it. Btw this is giving out the exact location i need but only for 10 seconds on serial monitor.
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.
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
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 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:
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);
}
}
}
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.