If IP address cant be reached (ping timeout) then..

Moderator: leecollings

Post Reply
Hcroij
Posts: 24
Joined: Sunday 27 November 2016 16:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

If IP address cant be reached (ping timeout) then..

Post by Hcroij »

Oke, would be easyer to buy a new router but....
Using a Asus rt-ac68U, dont know whats wrong but once in a while the thing freezes and the only option is "pull the plug"
No cron jobs or scripts helping "Freeze" is a block of solid ice.

I am fairly new in domotics, searched the forum but vould not find it or (obvious) I am not clever enough to..
I am looking for a possibillity like...

If ip 8.8.8.8 (google) can not be reached for xx seconds..
AND
if ip x.x.x.x (router external ip) can not be reached for x seconds
THEN
.... Turn of "powerswitch" for 30 secs.

Basically..
I want to check if an externap ip address is still alive.

For the IT specialist among us.. somehow a watchdog cron job does not work in a freeze.

Regards
Henk Croijmans
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: If IP address cant be reached (ping timeout) then..

Post by Egregius »

In pass2php I would handle that like this:

Code: Select all

<?php
if(apcu_fetch('srouter')=='On'){
    if(pingport('192.168.2.1',80)==1){
        $prevcheck=apcu_fetch('check192.168.2.1:80');
        if($prevcheck>0)apcu_store('check192.168.2.1:80',0);
    }else{
        $check=apcu_fetch('check192.168.2.1:80')+1;
        if($check>0)apcu_store('check192.168.2.1:80',$check);
        if($check>=3){
            sw('router','Off');
            sleep(5);
            sw('router','On');
        }
    }
}else sw('router','On');
 
Hcroij
Posts: 24
Joined: Sunday 27 November 2016 16:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: If IP address cant be reached (ping timeout) then..

Post by Hcroij »

Great thx.
Ill keep you posted as soon it is implemented and tested.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest