arping als Zusatzvariante

master
Hofei 5 years ago
parent 9743dedcb4
commit cb5e1adc24

@ -12,6 +12,18 @@ import toml
import neopixel
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_COUNT = 60 # Number of LED pixels.
@ -60,12 +72,10 @@ class Uhr:
self.set_helligkeit(self.helligkeit)
# # # # # # # # # #
# GPIO:
# # # # # # # # # #
# GPIO
I_MODE_TASTER = gpiozero.Button(3)
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
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
return (0 | !0) 0 wenn erreichbar"""
befehl = "ping -c2 -W1 {}".format(ip)
@ -164,11 +174,16 @@ def check_anwesenheit(uhr):
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())["ping"]
def ping_arping(ip, interface):
"""pingt die IP 3x an
return (0 | !0) 0 wenn erreichbar
"""
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 = []
delta = datetime.timedelta(seconds=301)
last = datetime.datetime.now()
@ -181,10 +196,12 @@ def check_anwesenheit(uhr):
for key_status in wlanliste.keys():
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)
if key_funkart == "ping":
status_return = ping_ping(ip)
elif key_funkart == "bt":
status_return = ping_bt(ip)
elif key_funkart == "arping":
status_return = ping_arping(ip, interface)
else:
status_return = False
if not status_return:

Loading…
Cancel
Save