Node-red-contrib-homekit-bridged: bridge problem after restarting the router.

Created on 26 May 2019  路  19Comments  路  Source: NRCHKB/node-red-contrib-homekit-bridged

I have established NODE-RED, on Raspberry. It is connected via Etnernet to the router. So if you restart the router, the bridge is no longer seen by the application Home. Although through the dashboard everything is normally controlled and read. P.S. I have a lock, and a temperature sensor switches the light on ESP 8266. It is necessary to restart NODE-RED.

bug

Most helpful comment

I wrote above - just change www.apple.com to the gateway IP

It is understand :)

and restart the node-red when the connection with the router is restored,

how to do that.

All 19 comments

Home.app keeps connection to node-red homekit bridge in the background. If you restart router then it is loosing the connection.

I know this is a problem but I need you to make some tests for me:

  • after router restart kill Home.app and open it again and see if it works now (give it couple of seconds to connect and sync)
  • run node-red in debug mode and paste logs here from the moment before router restart to the end of it, remember to open Home.app and see if it works before you restart the router (before you paste logs have a look if there are any sensitive data)

1.On the first point. I did it more than once, even rebooted the iphone. the problem is solved only restart Node-red
2.I'm not very good at Linux , tell me more how to do it? Node-red installed on raspbian os.

Thanks for the answer for 1. No I need some more data.

To run node-red in debug instead of calling node-red you do:
DEBUG=NRCHKB,Accessory,HAPServer,EventedHTTPServer node-red

  • run node-red in debug mode and paste logs here from the moment before router restart to the end of it, remember to open Home.app and see if it works before you restart the router (before you paste logs have a look if there are any sensitive data)

log
or GoogleDrive Logs

Sorry that you had to wait so long.
Your log looks quite good to me.
I will try to make the same situation happen on my environment.

Workaround would be to add a service that check for internet connection.
If there is no internet that it waits until it is back and resets whole node-red.

I have tried restarting my router twice.
For the first time in indeed not connected again.
But second time it did and continued to work without node-red restart.

Hi I have the same problem here. But restarting router twice (FB7490) did not work.
I have several nodes for himekit with different devices each (window shades, temperature sensors, etc)
Effect was: some nodes were still working after first reboot and stopped working after second ...
After a reboot of my pi's (node red restart) it worked fine...

I feel like this Issue should be created on https://github.com/KhaosT/HAP-NodeJS
We don't manage connection directly, it's on HAP-NodeJS side.

I can propose again to create process on your workstation that will look for router restart and will restart node-red accordingly.

"create process on your workstation that will look for router restart and will restart node-red accordingly"

I thought about that too. Now, if someone could help write a script that will ping my gateway and restart it, I'm not very strong Linux

What if you ping a website every 20 seconds - then restart after a string of failed pings finally comes back working?

I've built an example pinging apple.com. It pings every 20 seconds. If there's no response in 5 seconds, it sends "false". If the switch node gets "false" then it starts a timer - but resets after another "false" input.

Basically if the connection goes down this will get false - false - false - false until the connection is back up - then the trigger will send to the exec node to restart.

Screen Shot 2019-06-24 at 2 27 55 PM

Paste this code block into the node red clipboard import:

[{"id":"dbfacac.7c374b8","type":"exec","z":"6f858e04.973de8","command":"sudo systemctl restart nodered.service","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Restart nodered","x":620,"y":60,"wires":[[],[],[]]},{"id":"4df8722e.7cf12c","type":"trigger","z":"6f858e04.973de8","op1":"","op2":"","op1type":"nul","op2type":"date","duration":"30","extend":true,"units":"s","reset":"","bytopic":"all","name":"","x":430,"y":60,"wires":[["dbfacac.7c374b8"]]},{"id":"78dd6fef.fd6648","type":"switch","z":"6f858e04.973de8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"false"}],"checkall":"true","repair":false,"outputs":1,"x":270,"y":60,"wires":[["4df8722e.7cf12c"]]},{"id":"5ef98386.112f3c","type":"ping","z":"6f858e04.973de8","name":"","host":"www.apple.com","timer":"20","x":100,"y":60,"wires":[["78dd6fef.fd6648"]]}]

(all of these nodes are built in to node-red)

Not really. You need to follow the Internet and the gateway (router), and restart the node-red when the connection with the router is restored, I can write the code in C :

void restart () // function check for restart Node-Red
{
boolean ping=true;
static boolean status=true;
// pingf ()- function function that pings my gateway
ping=pingf();
if (ping==false && status==true) // if lost ping to gateway
{
status=false;
}
if (ping==true && status==false)//if the ping recovered but not before it had lost communication restart node-red
{
status=true;
node-red-restart();
}
}

how to implement this in Node-Red

Seems like that鈥檚 about the same as I wrote above - just change www.apple.com to the gateway IP?

Or are you saying that you need to check both local internet (gateway) and full internet (external)?

I wrote above - just change www.apple.com to the gateway IP

It is understand :)

and restart the node-red when the connection with the router is restored,

how to do that.

If you want to check local AND external - then duplicate the first two nodes, change one of the pings to gateway IP, and send both into the trigger. Should wait to restart until you have a gateway and apple.com connection!

I believe you鈥檙e asking how to make my flow restart nodered? The red node is an exec node - the command it will run is the Linux command to restart nodered, assuming it鈥檚 running as a system service, the normal way to run it on a raspberry pi- as that鈥檚 where I run.

Need a moment when communication with the gateway was restored and only then restart node-red. Internet check is not necessary, everything works locally. Above I wrote the code in C with an approximate algorithm. Went to study JS :)

What is the status of this Issue?

until took advantage of the offer crxporter
just like this:

[{"id":"520a6dca.ed2df4","type":"ping","z":"ed675b64.252008","name":"","host":"192.168.0.1","timer":"20","x":74,"y":543,"wires":[["770947.8d7446b8"]]},{"id":"770947.8d7446b8","type":"switch","z":"ed675b64.252008","name":"","property":"payload","propertyType":"msg","rules":[{"t":"false"}],"checkall":"true","repair":false,"outputs":1,"x":228,"y":543,"wires":[["9940b5fa.d44e28","4c6b5782.daa8f8"]]},{"id":"9940b5fa.d44e28","type":"trigger","z":"ed675b64.252008","op1":"","op2":"true","op1type":"nul","op2type":"bool","duration":"30","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":371,"y":542,"wires":[["b4f4e34.263662","4c6b5782.daa8f8"]]}]
only check every 20 sec. the trigger for 30 seconds. and resets when a new signal is received. I. e. if the router does not respond, the reboot will be only after the router responds to the ping.

I am closing this as it is inactive. Please free to comment or open a new one if required.
Solution for a problem is to create a node-red flow that will restart node-red.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

djiwondee picture djiwondee  路  4Comments

crxporter picture crxporter  路  3Comments

michaltaberski picture michaltaberski  路  6Comments

sjorge picture sjorge  路  7Comments

Shaquu picture Shaquu  路  9Comments