Added LED for internet connectivity check

This commit is contained in:
dbroqua 2021-01-25 10:15:56 +01:00
parent df1041ac14
commit 9a997f5bf3
3 changed files with 31 additions and 1 deletions

View File

@ -1,13 +1,19 @@
[adc]
# GPIOs pins
CLK = 11
MISO = 9
MOSI = 10
CS = 8
[button]
# GPIO Pin
# GPIO pin
BUTTON = 5
[network]
# GPIO pin
LED = 4
URL = http://www.darkou.fr
[display]
# Model: 7x4, 14x4
MODEL = 7x4

21
network.py Normal file
View File

@ -0,0 +1,21 @@
import RPi.GPIO as GPIO
from urllib import request
class Network:
"""Class to check network connectivity and display result"""
def __init__(self, config):
self.ledpin = int(config.get('network', 'LED'))
GPIO.setup(self.ledpin, GPIO.OUT)
GPIO.output(self.ledpin, GPIO.LOW)
self.host = config.get('network', 'URL')
def check(self):
try:
request.urlopen(self.host)
GPIO.output(self.ledpin, GPIO.HIGH)
return True
except:
GPIO.output(self.ledpin, GPIO.LOW)
return False

View File

@ -5,12 +5,14 @@ import RPi.GPIO as GPIO
from sensors import Sensors
from display import Display
from network import Network
config = configparser.RawConfigParser()
config.read(r'./config.ini')
display = Display(config)
sensor = Sensors(config)
network = Network(config)
# Init program
@ -50,6 +52,7 @@ def main():
print("Let's go!")
while True:
network.check()
display.print(sensor.getValue())
# Wait before next loop