Skip to content

Instantly share code, notes, and snippets.

@aadps
Last active July 5, 2021 17:28
Show Gist options
  • Save aadps/be8c338dbc13ab3b3ed8526b70ec062e to your computer and use it in GitHub Desktop.
Save aadps/be8c338dbc13ab3b3ed8526b70ec062e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
import requests
import os
RED=22
YELLOW=27
GREEN=17
HOME="http://192.168.1.1"
BAIDU="http://www.baidu.com"
PROXY="http://lx321.net"
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(RED,GPIO.OUT)
GPIO.setup(YELLOW,GPIO.OUT)
GPIO.setup(GREEN,GPIO.OUT)
while True:
GPIO.output(RED,GPIO.LOW)
GPIO.output(YELLOW,GPIO.LOW)
GPIO.output(GREEN,GPIO.LOW)
try:
if requests.get(HOME).ok:
GPIO.output(RED,GPIO.HIGH)
if requests.get(BAIDU).ok:
GPIO.output(YELLOW,GPIO.HIGH)
if requests.get(PROXY,proxies={'http':'socks5://localhost:1080'},timeout=5).ok:
GPIO.output(GREEN,GPIO.HIGH)
else:
os.system("systemctl restart autossh2.service")
except requests.exceptions.RequestException as e:
os.system("systemctl restart autossh2.service")
print e
time.sleep(240)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment