04/19/2019
Cheap automated device reboot via power cycle (EdgeRouter controlled WiFi PowerBar)
Used Products
×1
Location
Burlington, ON, Canada
Description

As MSP we're striving to control and manage everything remotely and keep service trips to minimal.

All of our customers are connected to Internet via Cable modem or DSL modem provided by ISP. The modem is typically in bridge mode and we don't have access to it.

When there's an ISP outage on rare occasions, especially on cable, the modem won't recover once the outage is over and we need either to call the customer to power-cycle the modem or drive over and do it ourselves.

 

We were looking into ethernet connected outlets with watchdog but there are not many and those we found are quite expensive.

 

So the idea was to build something cheap and control it from existing device, in our case we typically always have EdgeRouter on site which perfectly suits the purpose.

 

So, we found a cheap ESP8266 based power strip on Amazon, such as THIS one or THIS one (both are the same model Wi-Fi Smart Power Strip SWB1)

 

Then we've re-flashed it with Tasmota sonoff firmware.

The bar has serial header, all it needs is to solder 5 pins and off you go with the flash (how-to is on Tasmota Wiki).

 

power_strip_SWB1.png

 

After flash the bar will present it's own SSID for you to connect and configure it for your WiFi.

Once wifi parameters are configured it'll reboot and you can access it for further configuration. Our settings are on screens below.

 

1) Configuration -> Configure Template

 

Screenshot_20190419_214222.png

 

2) Configuration -> Configure Module

 

Screenshot_20190419_214334.png

 

3) Configuration -> Configure Other

 

Screenshot_20190419_214302.png

4) Via web console enter following commands.

These will ensure that after power loss all relays are turned on.

Each realy is set to 5 seconds pulse. Once you turn it off or toggle, it'll always trun itself back on after 5 seconds.

All Tasmota commands are described in detail HERE.

 

PowerOnState=5
PulseTime1=50
PulseTime2=50
PulseTime3=50
PulseTime4=50

The power bar is connected via Wi-Fi and does not support SSL, which is not ideal, but given the stellar reliability of UniFi APs we're not worried. To mitigate access concerns separate VLAN/SSID is probably a good idea. The interface supports password too (no SSL however).

 

Lastly, we've placed following Internet watchdog scrip on the EdgeRouter that runs every five minutes and tries to determine if Internet is up. If Internet is down, it'll power-cycle ISP modem every 30 minutes.

Mind, this is a fall-back for rare scenarios only when the modem has issues re-connecting after outage. In most situations this is not needed, in most clients wee have dual ISP connectivity allwowing us to gain access.

Here's the watchdog script placed in /config/scripts/inet-watchdog.sh called via task-scheduler every 5 minutes.

#!/bin/bash 

# add WAN interfaces
interfaces=(
   "eth0"
   "pppoe0"
)

power_bar="172.20.3.136"

# add your ping targets here  
targets=(
   "8.8.8.8"
   "2.16.40.66"
   "4.2.2.2"
   "1.1.1.1"
)

stat_file=/tmp/inet-watchdog.tmp

# let's try all interfaces and all targets
# as long as one responds we're assuming Internet is reachable
for interface in "${interfaces[@]}"
do
   for target in "${targets[@]}"
   do
       /bin/ping -q -n -c 1 -W 1 -w 1 -I $interface $target > /dev/null
       if [ $? == 0 ]
       then
#           echo "Internet reachable"
           rm -f $stat_file
           exit 0
       fi
   done
done

# internet NOT reachable
now_timestamp=$(date +%s)

if [ ! -e $stat_file ]
then
   echo $now_timestamp > $stat_file
fi

last_timestamp=$(cat $stat_file)
interval=$(($now_timestamp - $last_timestamp))

# Internet NOT reachable for 30 minutes
# Let's powercycle the modem
if [ $interval -gt 1800 ]
then
#    echo "Power cycling ISP modem on outlet1 ... Power1"
   message=$(curl -s http://$power_bar/cm?cmnd=Power1%20TOGGLE 2>&1)
   logger inet-watchdog $message
   rm -f $stat_file
fi

exit 1

The scrip and concept is rather rough, but it meets our needs. Next step is to eliminate WiFi and connect the power bar to RPi via GPIO directly (remove the ESP8266 from the picture). ...well, if the wifi proves to work reliably maybe we just leave it Man Wink

 

...I know this is not exactly EdgeMax story, however I though I'd share it anyway, maybe somebody will find it useful or it'll inspire for other solution or use case ...in which case please share back Man Wink

Cheap automated device reboot via power cycle (EdgeRouter controlled WiFi PowerBar)

by on ‎04-19-2019 07:08 PM - last edited a month ago

As MSP we're striving to control and manage everything remotely and keep service trips to minimal.

All of our customers are connected to Internet via Cable modem or DSL modem provided by ISP. The modem is typically in bridge mode and we don't have access to it.

When there's an ISP outage on rare occasions, especially on cable, the modem won't recover once the outage is over and we need either to call the customer to power-cycle the modem or drive over and do it ourselves.

 

We were looking into ethernet connected outlets with watchdog but there are not many and those we found are quite expensive.

 

So the idea was to build something cheap and control it from existing device, in our case we typically always have EdgeRouter on site which perfectly suits the purpose.

 

So, we found a cheap ESP8266 based power strip on Amazon, such as THIS one or THIS one (both are the same model Wi-Fi Smart Power Strip SWB1)

 

Then we've re-flashed it with Tasmota sonoff firmware.

The bar has serial header, all it needs is to solder 5 pins and off you go with the flash (how-to is on Tasmota Wiki).

 

power_strip_SWB1.png

 

After flash the bar will present it's own SSID for you to connect and configure it for your WiFi.

Once wifi parameters are configured it'll reboot and you can access it for further configuration. Our settings are on screens below.

 

1) Configuration -> Configure Template

 

Screenshot_20190419_214222.png

 

2) Configuration -> Configure Module

 

Screenshot_20190419_214334.png

 

3) Configuration -> Configure Other

 

Screenshot_20190419_214302.png

4) Via web console enter following commands.

These will ensure that after power loss all relays are turned on.

Each realy is set to 5 seconds pulse. Once you turn it off or toggle, it'll always trun itself back on after 5 seconds.

All Tasmota commands are described in detail HERE.

 

PowerOnState=5
PulseTime1=50
PulseTime2=50
PulseTime3=50
PulseTime4=50

The power bar is connected via Wi-Fi and does not support SSL, which is not ideal, but given the stellar reliability of UniFi APs we're not worried. To mitigate access concerns separate VLAN/SSID is probably a good idea. The interface supports password too (no SSL however).

 

Lastly, we've placed following Internet watchdog scrip on the EdgeRouter that runs every five minutes and tries to determine if Internet is up. If Internet is down, it'll power-cycle ISP modem every 30 minutes.

Mind, this is a fall-back for rare scenarios only when the modem has issues re-connecting after outage. In most situations this is not needed, in most clients wee have dual ISP connectivity allwowing us to gain access.

Here's the watchdog script placed in /config/scripts/inet-watchdog.sh called via task-scheduler every 5 minutes.

#!/bin/bash 

# add WAN interfaces
interfaces=(
   "eth0"
   "pppoe0"
)

power_bar="172.20.3.136"

# add your ping targets here  
targets=(
   "8.8.8.8"
   "2.16.40.66"
   "4.2.2.2"
   "1.1.1.1"
)

stat_file=/tmp/inet-watchdog.tmp

# let's try all interfaces and all targets
# as long as one responds we're assuming Internet is reachable
for interface in "${interfaces[@]}"
do
   for target in "${targets[@]}"
   do
       /bin/ping -q -n -c 1 -W 1 -w 1 -I $interface $target > /dev/null
       if [ $? == 0 ]
       then
#           echo "Internet reachable"
           rm -f $stat_file
           exit 0
       fi
   done
done

# internet NOT reachable
now_timestamp=$(date +%s)

if [ ! -e $stat_file ]
then
   echo $now_timestamp > $stat_file
fi

last_timestamp=$(cat $stat_file)
interval=$(($now_timestamp - $last_timestamp))

# Internet NOT reachable for 30 minutes
# Let's powercycle the modem
if [ $interval -gt 1800 ]
then
#    echo "Power cycling ISP modem on outlet1 ... Power1"
   message=$(curl -s http://$power_bar/cm?cmnd=Power1%20TOGGLE 2>&1)
   logger inet-watchdog $message
   rm -f $stat_file
fi

exit 1

The scrip and concept is rather rough, but it meets our needs. Next step is to eliminate WiFi and connect the power bar to RPi via GPIO directly (remove the ESP8266 from the picture). ...well, if the wifi proves to work reliably maybe we just leave it Man Wink

 

...I know this is not exactly EdgeMax story, however I though I'd share it anyway, maybe somebody will find it useful or it'll inspire for other solution or use case ...in which case please share back Man Wink

{"location":{"title":"Burlington, ON, Canada","placeId":"ChIJt5NdltJjK4gRT1UrTHYnSqQ"},"addedProducts":[{"id":"edgerouter-x","count":1}],"solved":"","numbers":"","description":"","mainImage":"202761i102DAB12A49A722E"}

Comments
by
on ‎04-20-2019 05:26 PM

I like the concept a lot!

 

This is the sort of solution that I always hoped Ubiqutii would begin

to include in its product lines. A modular building-block strategy

to add features such as remote control and monitoring was what

mFi was originally supposed to be. But it wasn't well integrated,

and there's a real place for innovation in the installer market.   Dave

by
a month ago

Far simpler IMHO to use the PoE output of an EdgeMAX device to power the modem. Then you can just cycle the modem power by cycling the PoE output. There are some cheap passive 24v PoE to 12V convertors on y that do the trick. https://www.amazon.co.uk/gp/product/B00EBCQ5FM/

by
3 weeks ago

I run into the same issues at our job sites. Cable modem needs a kick in the ass. I use this:

 

https://www.amazon.com/MSNSwitch-Internet-Enabled-Outlets-Interface/dp/B015NM0LKI/ref=sr_1_1_sspa?ke...

 

Power cycles my equipment if the VPN fails and Power cycles the modem if the internet is unreachable. set a schedule to reset them, or via Skype. These are great at the two owners houses where I hate telling them to reset.  Or they have to reset.  I plug these into our UPS and wire them to the network. NO wifi. 

 

A little more money for hardware but you will save in Labor and hassle. 

 

Neat project. Good luck with it. 

by
2 weeks ago

Definitely need it power cycling Addon to unifi.