|
|
@ -4,7 +4,6 @@ import datetime
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import shlex
|
|
|
|
import shlex
|
|
|
|
import subprocess
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import threading
|
|
|
|
import threading
|
|
|
|
import time
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
|
@ -17,9 +16,8 @@ import board
|
|
|
|
# LED strip configuration
|
|
|
|
# LED strip configuration
|
|
|
|
LED_COUNT = 60 # Number of LED pixels.
|
|
|
|
LED_COUNT = 60 # Number of LED pixels.
|
|
|
|
LED_PIN = board.D18 # GPIO pin connected to the pixels (must support PWM!).
|
|
|
|
LED_PIN = board.D18 # GPIO pin connected to the pixels (must support PWM!).
|
|
|
|
LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
|
|
|
|
|
|
|
|
LED_PIXEL_ORDER = neopixel.GRB # Strip type and colour ordering
|
|
|
|
LED_PIXEL_ORDER = neopixel.GRB # Strip type and colour ordering
|
|
|
|
LED_BRIGHTNESS = 0.2
|
|
|
|
LED_BRIGHTNESS = 0.1
|
|
|
|
|
|
|
|
|
|
|
|
# Zahl stellt den Wert in Minuten dar, wie lange kein Gerät erreichbar sein darf dass die Uhr "abgeschalten" wird
|
|
|
|
# Zahl stellt den Wert in Minuten dar, wie lange kein Gerät erreichbar sein darf dass die Uhr "abgeschalten" wird
|
|
|
|
ABSCHALTWERT = 4
|
|
|
|
ABSCHALTWERT = 4
|
|
|
@ -40,6 +38,16 @@ std11 = [54, 55, 56]
|
|
|
|
stdliste = [std0, std1, std2, std3, std4, std5, std6, std7, std8, std9, std10, std11]
|
|
|
|
stdliste = [std0, std1, std2, std3, std4, std5, std6, std7, std8, std9, std10, std11]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Uhr:
|
|
|
|
|
|
|
|
def __init__(self, pixels):
|
|
|
|
|
|
|
|
self.helligkeit = pixels.brightness
|
|
|
|
|
|
|
|
self.pixels = pixels
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_helligkeit(self, helligkeit):
|
|
|
|
|
|
|
|
self.helligkeit = helligkeit
|
|
|
|
|
|
|
|
self.pixels.brightness = self.helligkeit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # # # # # # # # #
|
|
|
|
# # # # # # # # # #
|
|
|
|
# GPIO:
|
|
|
|
# GPIO:
|
|
|
|
# # # # # # # # # #
|
|
|
|
# # # # # # # # # #
|
|
|
@ -123,23 +131,17 @@ def shutdown():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Threads
|
|
|
|
# Threads
|
|
|
|
def check_anwesenheit(pixels):
|
|
|
|
def check_anwesenheit(uhr):
|
|
|
|
"""Funktion, welche als eigener Thread laeuft, um selbststaendig in einem gewissenen Intervall
|
|
|
|
"""Funktion, welche als eigener Thread laeuft, um selbststaendig in einem gewissenen Intervall
|
|
|
|
alle Geraete in der Toml Liste zu pingen
|
|
|
|
alle Geraete in der Toml Liste zu pingen
|
|
|
|
arg: Objekt des neopixel LED Ringes
|
|
|
|
arg: Objekt des neopixel LED Ringes
|
|
|
|
toml File: status "anwesend", ist kein Geraet von "anwesend" oder "dimmen" erreichbar, LED Helligkeit auf 0
|
|
|
|
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"""
|
|
|
|
sobald eine Adresse von status "dimmen" erreichbar ist, wird die Helligkeit verringert"""
|
|
|
|
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):
|
|
|
|
def ping_device(mac):
|
|
|
|
"""pingt die IP 2x an
|
|
|
|
"""pingt das Gerät 2x an
|
|
|
|
return (0 | !0) 0 wenn erreichbar"""
|
|
|
|
return (0 | !0) 0 wenn erreichbar"""
|
|
|
|
befehl = "sudo /usr/bin/l2ping -c1 -t1 {}".format(bt)
|
|
|
|
befehl = "sudo arping -c2 {}".format(mac)
|
|
|
|
cmd = shlex.split(befehl)
|
|
|
|
cmd = shlex.split(befehl)
|
|
|
|
return subprocess.call(cmd)
|
|
|
|
return subprocess.call(cmd)
|
|
|
|
|
|
|
|
|
|
|
@ -147,29 +149,23 @@ def check_anwesenheit(pixels):
|
|
|
|
pfad = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
pfad = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
configfile = os.path.join(pfad, "bt_wlan.toml")
|
|
|
|
configfile = os.path.join(pfad, "bt_wlan.toml")
|
|
|
|
with open(configfile) as conffile:
|
|
|
|
with open(configfile) as conffile:
|
|
|
|
wlanliste = toml.loads(conffile.read())
|
|
|
|
wlanliste = toml.loads(conffile.read())["arping"]
|
|
|
|
status_anwesend_liste = []
|
|
|
|
status_anwesend_liste = []
|
|
|
|
delta = datetime.timedelta(seconds=301)
|
|
|
|
delta = datetime.timedelta(seconds=301)
|
|
|
|
last = datetime.datetime.now()
|
|
|
|
last = datetime.datetime.now()
|
|
|
|
status = {}
|
|
|
|
status = {}
|
|
|
|
while True:
|
|
|
|
while True:
|
|
|
|
now = datetime.datetime.now()
|
|
|
|
now = datetime.datetime.now()
|
|
|
|
# Status der IP Adressen ermitteln
|
|
|
|
# Status der Geräte ermitteln
|
|
|
|
if delta.seconds > 300:
|
|
|
|
if delta.seconds > 300:
|
|
|
|
for key_status in wlanliste.keys():
|
|
|
|
for key_status in wlanliste.keys():
|
|
|
|
for key_funkart in wlanliste[key_status].keys():
|
|
|
|
for mac in wlanliste[key_status]:
|
|
|
|
for ip in wlanliste[key_status][key_funkart]:
|
|
|
|
status_return = ping_device(mac)
|
|
|
|
if key_funkart == "wlan":
|
|
|
|
if not status_return:
|
|
|
|
status_return = ping_wlan(ip)
|
|
|
|
status[key_status] = True
|
|
|
|
elif key_funkart == "bt":
|
|
|
|
break
|
|
|
|
status_return = ping_bt(ip)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
status[key_status] = False
|
|
|
|
status_return = False
|
|
|
|
|
|
|
|
if not status_return:
|
|
|
|
|
|
|
|
status[key_status] = True
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
status[key_status] = False
|
|
|
|
|
|
|
|
if status["anwesend"]:
|
|
|
|
if status["anwesend"]:
|
|
|
|
status_anwesend_liste = [] # Geraet von anwesend erreichbar
|
|
|
|
status_anwesend_liste = [] # Geraet von anwesend erreichbar
|
|
|
|
helligkeit = LED_BRIGHTNESS
|
|
|
|
helligkeit = LED_BRIGHTNESS
|
|
|
@ -183,7 +179,7 @@ def check_anwesenheit(pixels):
|
|
|
|
helligkeit = LED_BRIGHTNESS * 0.5
|
|
|
|
helligkeit = LED_BRIGHTNESS * 0.5
|
|
|
|
if now.hour < 5 and not status["dimmen"]:
|
|
|
|
if now.hour < 5 and not status["dimmen"]:
|
|
|
|
helligkeit = 0
|
|
|
|
helligkeit = 0
|
|
|
|
pixels.brightness = helligkeit
|
|
|
|
uhr.set_helligkeit(helligkeit)
|
|
|
|
last = datetime.datetime.now()
|
|
|
|
last = datetime.datetime.now()
|
|
|
|
delta = now - last
|
|
|
|
delta = now - last
|
|
|
|
time.sleep(30)
|
|
|
|
time.sleep(30)
|
|
|
@ -196,21 +192,20 @@ def main():
|
|
|
|
pixels = neopixel.NeoPixel(LED_PIN, LED_COUNT, brightness=LED_BRIGHTNESS,
|
|
|
|
pixels = neopixel.NeoPixel(LED_PIN, LED_COUNT, brightness=LED_BRIGHTNESS,
|
|
|
|
auto_write=False, pixel_order=LED_PIXEL_ORDER)
|
|
|
|
auto_write=False, pixel_order=LED_PIXEL_ORDER)
|
|
|
|
|
|
|
|
|
|
|
|
thread_check_wlan = threading.Thread(target=check_anwesenheit, args=(pixels,))
|
|
|
|
uhr = Uhr(pixels)
|
|
|
|
|
|
|
|
thread_check_wlan = threading.Thread(target=check_anwesenheit, args=(uhr,))
|
|
|
|
thread_check_wlan.start()
|
|
|
|
thread_check_wlan.start()
|
|
|
|
alle_led(rgbconf["rgb_leer"][0], rgbconf["rgb_leer"][1], rgbconf["rgb_leer"][2], pixels)
|
|
|
|
alle_led(rgbconf["rgb_leer"][0], rgbconf["rgb_leer"][1], rgbconf["rgb_leer"][2], pixels)
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
while True:
|
|
|
|
rgbconf = rgb_standard()
|
|
|
|
rgbconf = rgb_standard()
|
|
|
|
now = datetime.datetime.now()
|
|
|
|
now = datetime.datetime.now()
|
|
|
|
if lastsecond != now.second:
|
|
|
|
if lastsecond != now.second:
|
|
|
|
lastsecond, led_gesetzt = led_calc(now, stdliste, rgbconf, led_gesetzt, pixels)
|
|
|
|
lastsecond, led_gesetzt = led_calc(now, stdliste, rgbconf, led_gesetzt, pixels)
|
|
|
|
time.sleep(0.2)
|
|
|
|
time.sleep(0.2)
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
finally:
|
|
|
|
print("KeyboardInterrupt")
|
|
|
|
pixels.brightness = 0
|
|
|
|
pixels.brightness = 0
|
|
|
|
alle_led(0, 0, 0, pixels)
|
|
|
|
alle_led(0, 0, 0, pixels)
|
|
|
|
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if __name__ == "__main__":
|
|
|
|