|
|
@ -12,6 +12,18 @@ import toml
|
|
|
|
import neopixel
|
|
|
|
import neopixel
|
|
|
|
import board
|
|
|
|
import board
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SKRIPTPFAD = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load_config(pfad=SKRIPTPFAD):
|
|
|
|
|
|
|
|
configfile = os.path.join(pfad, "uhr_cfg.toml")
|
|
|
|
|
|
|
|
with open(configfile) as conffile:
|
|
|
|
|
|
|
|
config = toml.loads(conffile.read())
|
|
|
|
|
|
|
|
return config
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CONFIG = load_config()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# LED strip configuration
|
|
|
|
# LED strip configuration
|
|
|
|
LED_COUNT = 60 # Number of LED pixels.
|
|
|
|
LED_COUNT = 60 # Number of LED pixels.
|
|
|
@ -60,12 +72,10 @@ class Uhr:
|
|
|
|
self.set_helligkeit(self.helligkeit)
|
|
|
|
self.set_helligkeit(self.helligkeit)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # # # # # # # # #
|
|
|
|
# GPIO
|
|
|
|
# GPIO:
|
|
|
|
|
|
|
|
# # # # # # # # # #
|
|
|
|
|
|
|
|
I_MODE_TASTER = gpiozero.Button(3)
|
|
|
|
I_MODE_TASTER = gpiozero.Button(3)
|
|
|
|
I_PLUS_TASTER = gpiozero.Button(4)
|
|
|
|
I_PLUS_TASTER = gpiozero.Button(4)
|
|
|
|
I_MINUS_TASTER = gpiozero.Button(14)
|
|
|
|
I_MINUS_TASTER = gpiozero.Button(17)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # # # # # # # # #
|
|
|
|
# # # # # # # # # #
|
|
|
@ -150,7 +160,7 @@ def check_anwesenheit(uhr):
|
|
|
|
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):
|
|
|
|
def ping_ping(ip):
|
|
|
|
"""pingt die IP 2x an
|
|
|
|
"""pingt die IP 2x an
|
|
|
|
return (0 | !0) 0 wenn erreichbar"""
|
|
|
|
return (0 | !0) 0 wenn erreichbar"""
|
|
|
|
befehl = "ping -c2 -W1 {}".format(ip)
|
|
|
|
befehl = "ping -c2 -W1 {}".format(ip)
|
|
|
@ -164,11 +174,16 @@ def check_anwesenheit(uhr):
|
|
|
|
cmd = shlex.split(befehl)
|
|
|
|
cmd = shlex.split(befehl)
|
|
|
|
return subprocess.call(cmd)
|
|
|
|
return subprocess.call(cmd)
|
|
|
|
|
|
|
|
|
|
|
|
# Tomlfile mit den IP Adressen einlesen
|
|
|
|
def ping_arping(ip, interface):
|
|
|
|
pfad = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
"""pingt die IP 3x an
|
|
|
|
configfile = os.path.join(pfad, "bt_wlan.toml")
|
|
|
|
return (0 | !0) 0 wenn erreichbar
|
|
|
|
with open(configfile) as conffile:
|
|
|
|
"""
|
|
|
|
wlanliste = toml.loads(conffile.read())["ping"]
|
|
|
|
befehl = "/usr/bin/arping -c 3 -w 10 -b -f -I {interface} {ip}".format(interface=interface, ip=ip)
|
|
|
|
|
|
|
|
cmd = shlex.split(befehl)
|
|
|
|
|
|
|
|
return subprocess.call(cmd)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wlanliste = CONFIG["ping"]
|
|
|
|
|
|
|
|
interface = CONFIG["interface"]
|
|
|
|
status_anwesend_liste = []
|
|
|
|
status_anwesend_liste = []
|
|
|
|
delta = datetime.timedelta(seconds=301)
|
|
|
|
delta = datetime.timedelta(seconds=301)
|
|
|
|
last = datetime.datetime.now()
|
|
|
|
last = datetime.datetime.now()
|
|
|
@ -181,10 +196,12 @@ def check_anwesenheit(uhr):
|
|
|
|
for key_status in wlanliste.keys():
|
|
|
|
for key_status in wlanliste.keys():
|
|
|
|
for key_funkart in wlanliste[key_status].keys():
|
|
|
|
for key_funkart in wlanliste[key_status].keys():
|
|
|
|
for ip in wlanliste[key_status][key_funkart]:
|
|
|
|
for ip in wlanliste[key_status][key_funkart]:
|
|
|
|
if key_funkart == "wlan":
|
|
|
|
if key_funkart == "ping":
|
|
|
|
status_return = ping_wlan(ip)
|
|
|
|
status_return = ping_ping(ip)
|
|
|
|
elif key_funkart == "bt":
|
|
|
|
elif key_funkart == "bt":
|
|
|
|
status_return = ping_bt(ip)
|
|
|
|
status_return = ping_bt(ip)
|
|
|
|
|
|
|
|
elif key_funkart == "arping":
|
|
|
|
|
|
|
|
status_return = ping_arping(ip, interface)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
status_return = False
|
|
|
|
status_return = False
|
|
|
|
if not status_return:
|
|
|
|
if not status_return:
|
|
|
|