Logic Machine Forum
Reset Router when Internet lost - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Reset Router when Internet lost (/showthread.php?tid=3267)



Reset Router when Internet lost - managementboy - 31.03.2021

I have my LogicMachine remotely behind a router. Sometimes the router looses the Internet for a minute and for unknown reasons the build in VPN does not restart. I have hooked up one KNX actor to the power of the router. Once a day I do I scripted on/off. That has solved the problem temporarily.

Question: how would I go about creating a script that checks if the Internet is available from the LM and if not sends an "off" and after a minute an "on" to the knx actor?

cheers!!!


RE: Reset Router when Internet lost - Daniel - 31.03.2021

Not sure if this is correct approach but you could try ping google.com. Use this script, you will get 0 on success.
Code:
ip = 'google.com'
res = os.execute('ping -c 2 -W 1 ' .. ip)
log(res)



RE: Reset Router when Internet lost - managementboy - 06.04.2021

(31.03.2021, 08:19)Daniel. Wrote: Not sure if this is correct approach but you could try ping google.com. Use this script, you will get 0 on success.
Code:
ip = 'google.com'
res = os.execute('ping -c 2 -W 1 ' .. ip)
log(res)

Thanks! So I did this:

Code:
ip = '192.168.0.1'
res = os.execute('ping -c 2 -W 1 ' .. ip)
if (res == 1) then
  log("Reboot due to VPN down")
  grp.write('4/1/2', false)
  os.sleep(1.5)
  grp.write('4/1/2', true)
end