I am using Blynk on an Arduino 101 via BLE to control a stepper motor.
All works great regarding speed control, positioning, etc…except that when running at a constant speed (any speed), with no commands or changes being sent via BLE, the stepper hiccups every 10 seconds (as best as I can time it).
Is there some function within Blynk.run(); that occurs on such a frequency?
Yes the heartbeat and without it you are dead.
Ahhh. Yes, I see this in the FAQ:
In ideal world when device closes tcp connection with some connection.close() - connected server will get notification regarding closed connection. So you can get instant status update on UI. However in real world this mostly exceptional situation. In majority of cases there is no easy and instant way to find out that connection is not active anymore.
That’s why Blynk uses HEARTBEAT mechanism. With this approach hardware periodically sends ping command with predefined interval (10 seconds by default, BLYNK_HEARTBEAT property). In case hardware don’t send anything within 10 seconds server waits additional 5 seconds and after that connection assumed to be broken and closed by server. So on UI you’ll see connection status update only after 15 seconds when it is actually happened.
You can also change HEARTBEAT interval from hardware side via Blynk.config. In that case newHeartbeatInterval * 2.3 formula will be applied. So in case you you decided to set HEARTBEAT interval to 5 seconds. You’ll get notification regarding connection with 11 sec delay in worst case.
Would be nice to be able to disable the heartbeat during a motor drive operation, and restart upon completion.
You can, disconnect and reconnect.
I don’t think disconnecting/reconnecting would work in my case due to the time that would take.
Is the heartbeat necessary to maintain the connection, or is it just a ping to verify connection?
And by ‘connection’, does this mean the connection between the app and the Blynk server, or the app and the BLE device?
For reliable stepper control, you either have to use a separate dedicated controller,.or multicore mcu, or run stepper completely from timer interrupts which is really tricky.
Yeah. Bummer. I had to run two arduinos when controlling the stepper over ethernet also, so this does not surprise me.
Question… so does this heartbeat apply to production/app store published versions of Blynk apps?
I mean, does a published version still need to connect to the Blynk server? And on that note…does that limit the use of Blynk apps to only use cases that have internet access while in use?