|
|
|
@ -17,7 +17,7 @@ import board
|
|
|
|
|
LED_COUNT = 60 # Number of LED pixels.
|
|
|
|
|
LED_PIN = board.D18 # GPIO pin connected to the pixels (must support PWM!).
|
|
|
|
|
LED_PIXEL_ORDER = neopixel.GRB # Strip type and colour ordering
|
|
|
|
|
LED_BRIGHTNESS = 0.1
|
|
|
|
|
LED_BRIGHTNESS = 0.05
|
|
|
|
|
|
|
|
|
|
# Zahl stellt den Wert in Minuten dar, wie lange kein Gerät erreichbar sein darf dass die Uhr "abgeschalten" wird
|
|
|
|
|
ABSCHALTWERT = 4
|
|
|
|
@ -47,6 +47,18 @@ class Uhr:
|
|
|
|
|
self.helligkeit = helligkeit
|
|
|
|
|
self.pixels.brightness = self.helligkeit
|
|
|
|
|
|
|
|
|
|
def helligkeit_erhoehen(self):
|
|
|
|
|
self.helligkeit += 0.05
|
|
|
|
|
if self.helligkeit > 1:
|
|
|
|
|
self.helligkeit = 0
|
|
|
|
|
self.set_helligkeit(self.helligkeit)
|
|
|
|
|
|
|
|
|
|
def helligkeit_verringern(self):
|
|
|
|
|
self.helligkeit -= 0.05
|
|
|
|
|
if self.helligkeit < 0:
|
|
|
|
|
self.helligkeit = 1
|
|
|
|
|
self.set_helligkeit(self.helligkeit)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # # # # # # # # #
|
|
|
|
|
# GPIO:
|
|
|
|
@ -138,18 +150,25 @@ def check_anwesenheit(uhr):
|
|
|
|
|
toml File: status "anwesend", ist kein Geraet von "anwesend" oder "dimmen" erreichbar, LED Helligkeit auf 0
|
|
|
|
|
sobald eine Adresse von status "dimmen" erreichbar ist, wird die Helligkeit verringert"""
|
|
|
|
|
|
|
|
|
|
def ping_device(mac):
|
|
|
|
|
"""pingt das Gerät 2x an
|
|
|
|
|
def ping_wlan(ip):
|
|
|
|
|
"""pingt die IP 2x an
|
|
|
|
|
return (0 | !0) 0 wenn erreichbar"""
|
|
|
|
|
befehl = "ping -c2 -W1 {}".format(ip)
|
|
|
|
|
cmd = shlex.split(befehl)
|
|
|
|
|
return subprocess.call(cmd)
|
|
|
|
|
|
|
|
|
|
def ping_bt(bt):
|
|
|
|
|
"""pingt die IP 2x an
|
|
|
|
|
return (0 | !0) 0 wenn erreichbar"""
|
|
|
|
|
befehl = "sudo arping -c2 {}".format(mac)
|
|
|
|
|
befehl = "sudo /usr/bin/l2ping -c1 -t1 {}".format(bt)
|
|
|
|
|
cmd = shlex.split(befehl)
|
|
|
|
|
return subprocess.call(cmd)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Tomlfile mit den IP Adressen einlesen
|
|
|
|
|
pfad = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
|
configfile = os.path.join(pfad, "bt_wlan.toml")
|
|
|
|
|
with open(configfile) as conffile:
|
|
|
|
|
wlanliste = toml.loads(conffile.read())["arping"]
|
|
|
|
|
wlanliste = toml.loads(conffile.read())["ping"]
|
|
|
|
|
status_anwesend_liste = []
|
|
|
|
|
delta = datetime.timedelta(seconds=301)
|
|
|
|
|
last = datetime.datetime.now()
|
|
|
|
@ -160,16 +179,22 @@ def check_anwesenheit(uhr):
|
|
|
|
|
# Status der Geräte ermitteln
|
|
|
|
|
if delta.seconds > 300:
|
|
|
|
|
for key_status in wlanliste.keys():
|
|
|
|
|
for mac in wlanliste[key_status]:
|
|
|
|
|
status_return = ping_device(mac)
|
|
|
|
|
if not status_return:
|
|
|
|
|
status[key_status] = True
|
|
|
|
|
break
|
|
|
|
|
else:
|
|
|
|
|
status[key_status] = False
|
|
|
|
|
for key_funkart in wlanliste[key_status].keys():
|
|
|
|
|
for ip in wlanliste[key_status][key_funkart]:
|
|
|
|
|
if key_funkart == "wlan":
|
|
|
|
|
status_return = ping_wlan(ip)
|
|
|
|
|
elif key_funkart == "bt":
|
|
|
|
|
status_return = ping_bt(ip)
|
|
|
|
|
else:
|
|
|
|
|
status_return = False
|
|
|
|
|
if not status_return:
|
|
|
|
|
status[key_status] = True
|
|
|
|
|
break
|
|
|
|
|
else:
|
|
|
|
|
status[key_status] = False
|
|
|
|
|
if status["anwesend"]:
|
|
|
|
|
status_anwesend_liste = [] # Geraet von anwesend erreichbar
|
|
|
|
|
helligkeit = LED_BRIGHTNESS
|
|
|
|
|
helligkeit = uhr.helligkeit
|
|
|
|
|
elif not status["anwesend"] and not status["dimmen"]: # Wenn kein Geraet erreichbar ist
|
|
|
|
|
if len(status_anwesend_liste) < ABSCHALTWERT + 1:
|
|
|
|
|
status_anwesend_liste.append(status["anwesend"])
|
|
|
|
@ -177,7 +202,7 @@ def check_anwesenheit(uhr):
|
|
|
|
|
if len(status_anwesend_liste) > ABSCHALTWERT:
|
|
|
|
|
helligkeit = 0
|
|
|
|
|
if status["dimmen"]:
|
|
|
|
|
helligkeit = LED_BRIGHTNESS * 0.5
|
|
|
|
|
helligkeit = uhr.helligkeit * 0.5
|
|
|
|
|
if now.hour < 5 and not status["dimmen"]:
|
|
|
|
|
helligkeit = 0
|
|
|
|
|
uhr.set_helligkeit(helligkeit)
|
|
|
|
@ -192,11 +217,14 @@ def main():
|
|
|
|
|
rgbconf = rgb_standard()
|
|
|
|
|
pixels = neopixel.NeoPixel(LED_PIN, LED_COUNT, brightness=LED_BRIGHTNESS,
|
|
|
|
|
auto_write=False, pixel_order=LED_PIXEL_ORDER)
|
|
|
|
|
|
|
|
|
|
uhr = Uhr(pixels)
|
|
|
|
|
thread_check_wlan = threading.Thread(target=check_anwesenheit, args=(uhr,))
|
|
|
|
|
thread_check_wlan.start()
|
|
|
|
|
alle_led(rgbconf["rgb_leer"][0], rgbconf["rgb_leer"][1], rgbconf["rgb_leer"][2], pixels)
|
|
|
|
|
|
|
|
|
|
I_PLUS_TASTER.when_pressed = uhr.helligkeit_erhoehen
|
|
|
|
|
I_MINUS_TASTER.when_pressed = uhr.helligkeit_verringern
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
while True:
|
|
|
|
|
rgbconf = rgb_standard()
|
|
|
|
|