Page 1 of 1

Wanting to reboot remote power

Posted: Mon Sep 29, 2014 2:09 pm
by smartmoney
n00b here so please be patient.

I'm wanting to reset remote outlets to reset devices over the internet when connectivity is lost (i have remote wi-fi installations that sometimes lock up and i need to drive there to reboot)

my setup is similar to http://www.instructables.com/id/Web-Con ... owerstrip/ with only 2 outlets. It is running with no issues. I can use the web browser to remotely switch the outlets on/off. What i need additional is have it monitor the network (like watchdog) and when internet (or ip address) is lost, send a command to the relay to reboot the outlet (off then back on)

I know there are devices like http://www.digital-loggers.com/lpc.html and i have one but its overkill plus i wanted something slightly different with a UPS so i just built one

Re: Wanting to reboot remote power

Posted: Mon Sep 29, 2014 5:45 pm
by hampi
In my case I can set the WIFIACT in the configuration file

https://github.com/oh7bf/PiPIC/blob/mas ... erd_config

but this system works from 12 V DC and not directly from mains power.

Re: Wanting to reboot remote power

Posted: Mon Sep 29, 2014 8:23 pm
by smartmoney
something along the lines of
ping 8.8.8.8 and if good do nothing
if fails then set gpio pin 17 to 0 (off) send this to my relay which shuts off one wired 120v outlet
then 5 sec pause
then set gpio pin 17 to 1 (on)send this to my relay which turns on one wired 120v outlet

is there somewhere to build this code myself? (i have no code building knowledge)

Re: Wanting to reboot remote power

Posted: Tue Sep 30, 2014 8:14 am
by DougieLawson

Code: Select all

#!/usr/bin/python3

import urllib.request, urllib.error
import RPi.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)

def errorHandler():
  print ('Error, wiggle pin #17')
  GPIO.output(17, GPIO.HIGH)
  sleep(5)
  GPIO.output(17, GPIO.LOW)

try:
  google = urllib.request.urlopen('http://google.com')

except urllib.error.URLError as e:
  errorHandler()

except socket.error as e:
  errorHandler()

else:
  print ('Google OK')

Re: Wanting to reboot remote power

Posted: Wed Oct 01, 2014 4:06 am
by wernermeurer
Hi!

Might it is an idea to use monit for this job.
http://mmonit.com/monit/
I used it on "non-RPIs" for similar jobs.

Good luck
Werner