-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheckconnection.py
More file actions
55 lines (43 loc) · 1.16 KB
/
checkconnection.py
File metadata and controls
55 lines (43 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import subprocess
import RPi.GPIO as GPIO
from time import sleep
RED = 32
GREEN = 36
BLINKSTATUS = GPIO.LOW
waitGreen = 1
waitRed = 0.2
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(RED, GPIO.OUT, initial=BLINKSTATUS)
GPIO.setup(GREEN, GPIO.OUT, initial=BLINKSTATUS)
host = "www.google.com"
def blink(led):
global BLINKSTATUS
print (BLINKSTATUS)
if (BLINKSTATUS==GPIO.HIGH):
BLINKSTATUS=GPIO.LOW
else:
BLINKSTATUS=GPIO.HIGH
print (BLINKSTATUS)
GPIO.output(led, BLINKSTATUS)
def shutdown(led):
GPIO.output(led, GPIO.LOW)
try:
while (True):
ping = subprocess.call("ping -c 1 www.google.com",
shell=True,
stdout=open('/dev/null', 'w'),
stderr=subprocess.STDOUT
)
if(ping==0):
print("BLINK GREEN")
shutdown(RED)
blink(GREEN)
sleep(waitGreen)
else:
print("BLINK RED")
shutdown(GREEN)
blink(RED)
sleep(waitRed)
finally:
GPIO.cleanup()