Added LED for internet connectivity check
This commit is contained in:
parent
df1041ac14
commit
9a997f5bf3
3 changed files with 31 additions and 1 deletions
|
@ -1,13 +1,19 @@
|
||||||
[adc]
|
[adc]
|
||||||
|
# GPIOs pins
|
||||||
CLK = 11
|
CLK = 11
|
||||||
MISO = 9
|
MISO = 9
|
||||||
MOSI = 10
|
MOSI = 10
|
||||||
CS = 8
|
CS = 8
|
||||||
|
|
||||||
[button]
|
[button]
|
||||||
# GPIO Pin
|
# GPIO pin
|
||||||
BUTTON = 5
|
BUTTON = 5
|
||||||
|
|
||||||
|
[network]
|
||||||
|
# GPIO pin
|
||||||
|
LED = 4
|
||||||
|
URL = http://www.darkou.fr
|
||||||
|
|
||||||
[display]
|
[display]
|
||||||
# Model: 7x4, 14x4
|
# Model: 7x4, 14x4
|
||||||
MODEL = 7x4
|
MODEL = 7x4
|
||||||
|
|
21
network.py
Normal file
21
network.py
Normal 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
|
|
@ -5,12 +5,14 @@ import RPi.GPIO as GPIO
|
||||||
|
|
||||||
from sensors import Sensors
|
from sensors import Sensors
|
||||||
from display import Display
|
from display import Display
|
||||||
|
from network import Network
|
||||||
|
|
||||||
config = configparser.RawConfigParser()
|
config = configparser.RawConfigParser()
|
||||||
config.read(r'./config.ini')
|
config.read(r'./config.ini')
|
||||||
|
|
||||||
display = Display(config)
|
display = Display(config)
|
||||||
sensor = Sensors(config)
|
sensor = Sensors(config)
|
||||||
|
network = Network(config)
|
||||||
|
|
||||||
|
|
||||||
# Init program
|
# Init program
|
||||||
|
@ -50,6 +52,7 @@ def main():
|
||||||
print("Let's go!")
|
print("Let's go!")
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
network.check()
|
||||||
display.print(sensor.getValue())
|
display.print(sensor.getValue())
|
||||||
|
|
||||||
# Wait before next loop
|
# Wait before next loop
|
||||||
|
|
Loading…
Reference in a new issue