App disconnecting on Android

Hi,

I have an App working on iPhone and getting disconnected 2-5 times a day.

I copied the same App to an Android and the NodeMCU is disconnecting from the server every minute or less. I know this by getting the push notification.

I can’t post the code here since it is few 1000’s of lines long.

Any help will be greatly appreciated.
Thanks
Sharon

Well… since all we can do is guess… I guess that something in your code is causing a heartbeat timeout and disconnection.

I am not sure this is the case since the same exact code on the NodeMCU device works pretty well on an iPhone.

Generally all the computing operation is on the device and the communication between the device and the Server… the App could be easily shut off and everything should still work… assuming user intervention in the App is not required. Thus the App or even project itself is less likely the cause of the disconnect.

Since all you should have needed to do was run the App on the same account on any Android/iOS phone/tablet, even multiple ones simultaneously… can you clarify what you meen by “copied”? As in cloned into another account or something?

I did clone the app and let another person to copy the Qcode to be able test it on an Android.

Then they are probably using different hardware, IDE setup, network, possibly different library versions and separate account, etc… so not conclusive to your diagnostics

Not really, the HW is exactly the same, the software that running on the NodeMCU is the exact same software.

How often the Hardware needs to invoke Blynk.run(); ?

I think it may be helpful if you can post your code. And Blynk.run(); should ideally be run every cycle.

Unless it is on the same network, using the same account, same power source, etc. it is not exactly the same :stuck_out_tongue:

Anyhow… to get back to the heart of the question… I suspect it is something in your code, but even if you posted it, our “job” as volunteers is not to troubleshoot your code, but give suggestions to assist your own troubleshooting. Like put in lots of Serial prints, possibly with time stamps, to monitor the stage of your code, if and when it disconnects.

As often as possible, which is why it, and mostly it alone (perhaps with something like timer.run(), etc.), is all that one should have in the void loop() thus running thousands of times a second.

http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/keep-your-void-loop-clean

As mentioned above the code includes few 1000’s of lines I am not sure we want to post it here. I am not sure what do you mean by cycle, the loop cycle can be 500ms and can be 50s. I am sure there is a specific time set.

Since the code is mostly interrupts based excpt the main loop, I am not sure how to define a timer interrupt with high priority to make sure the Blynk.run() is executed. How often should I interrupt the code and execute the Blynk.run();

You don’t need to invoke interrupts.

Can you post your void setup and void loop?

You simply leave Blynk.run() in the void loop()… all the rest of your code can run with interrupts or timers as you wish. However, be aware that if any one process takes longer than the heartbeat, Blynk will disconnect. Thus it is important to keep your coded routines/functions quick and to the point, always returning to the main loop ASAP… And don’t use blocking commands like delay() while(), and so on…

That’s exactly my suspicious, BTW I am running BlynkProvisioning.run(); and not Blynk.run() since I am using dynamic provisioning. I guess it is the same from this point of view.

I am also not sure what is ASAP, what is the timeout period that blynk will disconnect?

As Soon As Possible :wink:

By default around 10 seconds

1 Like

Thanks, whats happen if I have a interrupt service that takes longer than this, if a new interrupt comes in does it interrupt the first service? Is there a way to set interrupt priorities for the timers?

Your hardware is not true multitasking, so if something triggers a function before a previous function finishes, then both are getting split attention in the processing cycle… along with trying to keep connected to the server.

Basically like most men like me, works great when focused on one task at a time, falls apart when constantly nitpicked to do multiple things at once :rofl:

1 Like