smartmoney
Posts: 3
Joined: Mon Sep 29, 2014 1:58 pm

Wanting to reboot remote power

Mon Sep 29, 2014 2:09 pm

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

hampi
Posts: 223
Joined: Fri May 31, 2013 11:29 am
Contact: Website

Re: Wanting to reboot remote power

Mon Sep 29, 2014 5:45 pm

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.

smartmoney
Posts: 3
Joined: Mon Sep 29, 2014 1:58 pm

Re: Wanting to reboot remote power

Mon Sep 29, 2014 8:23 pm

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)

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Wanting to reboot remote power

Tue Sep 30, 2014 8:14 am

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')
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

wernermeurer
Posts: 7
Joined: Tue Sep 30, 2014 4:41 am

Re: Wanting to reboot remote power

Wed Oct 01, 2014 4:06 am

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

Return to “Beginners”