diff --git a/config.ini b/config.ini index 9f4f7bc..7595dc1 100644 --- a/config.ini +++ b/config.ini @@ -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 diff --git a/network.py b/network.py new file mode 100644 index 0000000..52f3f46 --- /dev/null +++ b/network.py @@ -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 diff --git a/raspicar.py b/raspicar.py index 0e5a1e6..e6bf410 100644 --- a/raspicar.py +++ b/raspicar.py @@ -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