Skip to content

Commit

Permalink
Fixing ports and gpio start conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkahn committed Dec 1, 2016
1 parent d0162ed commit 07865a4
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
13 changes: 3 additions & 10 deletions .idea/deployment.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/watchdoghandler.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 17 additions & 7 deletions netrepair.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@
import yaml
from datetime import timedelta

# todo add some checks to the VPN?
# TODO add some checks to the VPN?

import RPi.GPIO as GPIO
import pyping
badping = 0
totalping = 0
null = open('/dev/null','a')

def RobustPing(dest):
global totalping, badping, null
print dest
if dest[0] == '~': # for testing set destinations to ~L ~R
if os.path.isfile(dest):
logit("Simulate good ping of "+dest)
return True
else:
logit("Simulate failed ping of "+dest)
return False
ok = False
cmd = 'ping -c 1 -W 1 ' + dest
# todo should make this a loop that tries until success or 10 failures
Expand All @@ -32,6 +39,7 @@ def RobustPing(dest):
return ok



def GetPrinterStatus():
global APIkey
hdr = {'X-Api-Key': APIkey}
Expand All @@ -56,24 +64,24 @@ def __init__(self, n, port, dt):
self.name = n
self.delaytime = dt
if self.pin <> 0:
GPIO.setup(port, GPIO.OUT, initial=0)
GPIO.setup(port, GPIO.OUT, initial=GPIO.HIGH)

def reset(self):
self.resettime = time.time()
if self.delaytime <> 0:
logit('Reset: ' + self.name + ' at ' + str(self.resettime))
if self.pin <> 0:
GPIO.output(self.pin, 1)
time.sleep(5)
GPIO.output(self.pin, 0)
time.sleep(5)
GPIO.output(self.pin, 1)
else:
# not controlling device
logit("No reset, not controlling:" + self.name)


def waitforit(self):
if self.delaytime <> 0:
logit('Waiting on '+n+' next action in '+str(self.resettime+self.delaytime-time.time()))
logit('Waiting on '+self.name+' next action in '+str(self.resettime+self.delaytime-time.time()))
return self.resettime + self.delaytime > time.time()
else:
# not controlling the device so never wait
Expand Down Expand Up @@ -152,12 +160,13 @@ def getuptime():
GPIO.cleanup()
sys.stdout = open('/home/pi/watchdog/master.log', 'a', 0)
sys.stderr = open('/home/pi/watchdog/master.err', 'a', 0)
with open('/home/pi/watchdog/netwatch.yaml') as y:
with open('./netwatch.yaml') as y:
params = yaml.load(y)

p = params['pinghosts']
routerIP = p['localip']
externalIP = p['remoteip']
print 'Router:',routerIP,'External:',externalIP

noaction = params['noaction']
basecycletime = params['cycletime'] # seconds
Expand All @@ -184,6 +193,7 @@ def getuptime():
p = params['printer']
monitorprinter = p['controlled']
offafter = prport = proffcmd = 0
prforcedoff = False
if monitorprinter:
APIkey = p['key']
offafter = p['offafter']*60
Expand Down
2 changes: 1 addition & 1 deletion netwatchpgaw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pinghosts:
modem:
controlled: true
bootwait: 4
port: 11
port: 1

router:
controlled: true
Expand Down

0 comments on commit 07865a4

Please sign in to comment.