Heartbeat / Connection Status

I am using Blynk with a Raspi Pi and Node-Red to control a robot. I need to stop the propel motors if I loose the connection. If there a way to read the connection status or a way to create a heartbeat between the I-Phone and Rasp Pi?

As I understand, most Blynk Connect commands are more related to the Hardware <-> Server link.

I would recommend making sure none of your motor drive commands is infinite. I.e. will keep the same active state until told otherwise.

Or even building in your own simple timer routine that monitors how long any motor related commands have lasted until some last state of change. E.g. if nothing has been sent from particular control widget in x seconds, do FULL STOP.

@SNorwood I think if you check the Blynk.connected() function you should be able to stop the motors.

Also include the following in loop():

  if (Blynk.connected()) {

At SimpleTimer intervals run something like this:

void timedFunction(){  
  // enter code here to be done at intervals including checking if still connected to Blynk
    // code here to stop motors

@Costas Perhaps I misunderstood the DOCs? What if his app loses connection to the server (app crash, incoming phone call, etc), but the hardware stays connected (to the server)?

To be honest I’m not sure @SNorwood will have to test and let us know.

@vshymanskyy / @Dmitriy if the app crashes, rather than a server disconnect, would Blynk.connected() function on the hardware still be effective?

@Costas yes. However it will notify regarding hardware connection to server and not app. I think we need to clarify here what exactly @SNorwood want to achieve and what does he mean by “if I loose the connection”.

I might have been taking this too literal… but then again, it is in reference to an active (real-time) robot control.

@SNorwood are you using a local or cloud server as it’s not clear if the Raspi Pi is just your MCU or server and MCU?

Probably not relevant to your question.

1 Like

Thank you for all the helpful replies.

Some clarifications: 1) I am currently using the cloud server but will switch to the server on the Pi once working. I want to stop motor commands when either the server or the client (I-Phone in this case) lose connection. For example, my motor controller stop motors when a signal is not received from the PI. Thus, I want to stop any commands when I lose connection to the “handset” (I-Phone in this case).

I am connecting through Node-Red and calling a python routine to control the motors.

From tests it looks like the BlynkConnect() only checks the status of the connection between the Rasp Pi and the Blynk server. It does not check the link all the way back to the IOS device.

I could write my code to ping the IOS device to at least confirm that it is still connected, but I don’t see a way to pull the IP address of the IOS device through the Blynk server. I cuold run a local server and use fixed IP addresses as a work-around around, but it would be useful to have a Blynk API that provides the IP address of the device connected.


I believe its not easy to get the IOS IP device address as you can have more than one devices connected to one project.

this is the same problem i have

As far as I know there is not a way to detect the IP address of the handheld device running Blynk. I use a Ping command on my Pi to check the connection status of the IOS device every 0.5 seconds as a heartbeat, but I have to load the IP address of the IOS device into my software. This works ok for me as I am controlling the robot only on my local network and I can force a fixed IP address.

My code is in Node-Red so it is difficult to post. However, my logic is as follows:

  1. If the joystick is not at neutral (stop) then send the drive command to the motors and start a loop that pings the IOS device every 1/2 second.
  2. My motor controller has a fail-safe that will stop the motors is a command is not received every x seconds.
    a) if the joystick moves a new drive command is sent to the motor controller. This resets the fail-safe
    b) if the joystick does not move then a successful ping results in a read from the motor controller that re-sets the fail-safe.
    c) when the joystick moves to neutral, the motors are set to stop and the loop generating the ping command stops.

if we had a widget whit a frequently blinking ( changing value ) we could use this for heardbeat to a virtual pin and if this value is not blinking = conection fail = stop motors

Agree. Either a separate widget or an option built into the joystick widget would make since I can’t think of the need to use a heartbeat with the other buttons / widgets. I checked my motor controller documentation at the default failsafe is 100 ms. It looks like the default failsafe on some RC receivers is 0.8 - 1 second.

How do I send a command to reconnect to blynk?

You mentioned the function “connect2Blynk();” but what could be inside it?

That is just a made up name for a function e.g. void connect2Blynk(); that contains whatever connection method works best for your hardware type and/or programming methods, etc…

PS, Please don’t ‘revive’ old topics like this… just spend a little time reading all the varied and numerous other topics, posts and documentation already present about this :wink: