Lately I’ve noticed that my devices go continuously ‘offline/online’ I’ve checked the wifi traffic and the the devices are physically online the whole time, hence I think its a heartbeat issue. Granted that I am running some heavy duty code on some devices (NO delay()s) so thats possibly the reason. At first I tried:
#define BLYNK_HEARTBEAT 20 // defaults to 10s.
#define BLYNK_TIMEOUT_MS 5000UL // defaults to 2000UL
but that made matters worse, so I reverted that. This resulted in less off/online issues but they still persist.
So I’m wondering whether there’s a heartbeat ping command I can spread among strategical places in my code to try to prevent the constant disconnect messages.
Perhaps your code is taking too long to execute, making involuntary delays you’re not aware of?
Just some light housekeeping i think
You can initiate it in other places, unless you run out of heap memory (in the cascaded functions with local memory). For example, it is not recommended to call Blynk.run() inside of the BLYNK_READ and BLYNK_WRITE functions on low-RAM devices.
small update: I think I’ve identified the issue: I initiate all the timers at setup() and they all run on a 1 minute interval…so basically I create a heartbeat bottleneck every minute, the reason I think this is the issue is that the disconnects dissapate over time (apparently as the timers slowly diverge).
So now I’m wondering whats the best action…
I could put a delay(1000) between the timers in the setup
I could cram all the routines into one function e.g. runAll() and put runAll() on a 1 minutes timer with blynk.begin() between each subroutine.
This is what it looks now:
Serial.println("Initiating all timed functions");
timer.setInterval(TIME_READ_SENSOR, updateCurrentT); // every 1 minute: read T
timer.setInterval(TIME_CHECK_HEATER, checkHeater); // every 1 minute: check if the heater needs to be turned on or off
timer.setInterval(TIME_CHECK_BUTTONS, checkButtons); // every 0.1 second: check if a button is pressed
timer.setInterval(TIME_RECONNECT_CHECK, reconnectBlynk); // every 1 minute: device still connected to server
timer.setInterval(TIME_UPDATE_TERMINAL_LABEL, updateTerminalLAbel); // every 1 minute: update the label on the terminal (time/wifi strength/version)
timer.setInterval(TIME_CHECK_SCHEDULE, checkSchedule); // every 1 minute: check timer schedule (night/day cycle)
yeah, you came to the exact same conclusion as I did, either seperate in time or put them all in one function. I’ll go for the latter as it gives more control and put a couple of blynk.run in them.
ill change the subject to solved for now as i think this will resolve the issue.