| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -17,7 +17,7 @@ import board
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					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_PIXEL_ORDER = neopixel.GRB   # Strip type and colour ordering
 | 
					 | 
					 | 
					 | 
					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
 | 
					 | 
					 | 
					 | 
					# Zahl stellt den Wert in Minuten dar, wie lange kein Gerät erreichbar sein darf dass die Uhr "abgeschalten" wird
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					ABSCHALTWERT = 4
 | 
					 | 
					 | 
					 | 
					ABSCHALTWERT = 4
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -47,6 +47,18 @@ class Uhr:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        self.helligkeit = helligkeit
 | 
					 | 
					 | 
					 | 
					        self.helligkeit = helligkeit
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        self.pixels.brightness = self.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:
 | 
					 | 
					 | 
					 | 
					# GPIO:
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -138,10 +150,17 @@ 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_device(mac):
 | 
					 | 
					 | 
					 | 
					    def ping_wlan(ip):
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        """pingt das Gerät 2x an
 | 
					 | 
					 | 
					 | 
					        """pingt die IP 2x an
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return (0 | !0) 0 wenn erreichbar"""
 | 
					 | 
					 | 
					 | 
					        return (0 | !0) 0 wenn erreichbar"""
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        befehl = "sudo arping -c2 {}".format(mac)
 | 
					 | 
					 | 
					 | 
					        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 /usr/bin/l2ping -c1 -t1 {}".format(bt)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        cmd = shlex.split(befehl)
 | 
					 | 
					 | 
					 | 
					        cmd = shlex.split(befehl)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return subprocess.call(cmd)
 | 
					 | 
					 | 
					 | 
					        return subprocess.call(cmd)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -149,7 +168,7 @@ def check_anwesenheit(uhr):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    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())["arping"]
 | 
					 | 
					 | 
					 | 
					        wlanliste = toml.loads(conffile.read())["ping"]
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    status_anwesend_liste = [] 
 | 
					 | 
					 | 
					 | 
					    status_anwesend_liste = [] 
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    delta = datetime.timedelta(seconds=301)
 | 
					 | 
					 | 
					 | 
					    delta = datetime.timedelta(seconds=301)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    last = datetime.datetime.now()
 | 
					 | 
					 | 
					 | 
					    last = datetime.datetime.now()
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -160,16 +179,22 @@ def check_anwesenheit(uhr):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        # Status der Geräte 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 mac in wlanliste[key_status]:
 | 
					 | 
					 | 
					 | 
					                for key_funkart in wlanliste[key_status].keys():
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    status_return = ping_device(mac)
 | 
					 | 
					 | 
					 | 
					                    for ip in wlanliste[key_status][key_funkart]:
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    if not status_return:
 | 
					 | 
					 | 
					 | 
					                        if key_funkart == "wlan":
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        status[key_status] = True
 | 
					 | 
					 | 
					 | 
					                            status_return = ping_wlan(ip)
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        break
 | 
					 | 
					 | 
					 | 
					                        elif key_funkart == "bt":
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    else:
 | 
					 | 
					 | 
					 | 
					                            status_return = ping_bt(ip)
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        status[key_status] = False
 | 
					 | 
					 | 
					 | 
					                        else:
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                            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 = uhr.helligkeit
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            elif not status["anwesend"] and not status["dimmen"]:  # Wenn kein Geraet erreichbar ist
 | 
					 | 
					 | 
					 | 
					            elif not status["anwesend"] and not status["dimmen"]:  # Wenn kein Geraet erreichbar ist
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                if len(status_anwesend_liste) < ABSCHALTWERT + 1:
 | 
					 | 
					 | 
					 | 
					                if len(status_anwesend_liste) < ABSCHALTWERT + 1:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    status_anwesend_liste.append(status["anwesend"])
 | 
					 | 
					 | 
					 | 
					                    status_anwesend_liste.append(status["anwesend"])
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -177,7 +202,7 @@ def check_anwesenheit(uhr):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                if len(status_anwesend_liste) > ABSCHALTWERT: 
 | 
					 | 
					 | 
					 | 
					                if len(status_anwesend_liste) > ABSCHALTWERT: 
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    helligkeit = 0  
 | 
					 | 
					 | 
					 | 
					                    helligkeit = 0  
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            if status["dimmen"]:
 | 
					 | 
					 | 
					 | 
					            if status["dimmen"]:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                helligkeit = LED_BRIGHTNESS * 0.5
 | 
					 | 
					 | 
					 | 
					                helligkeit = uhr.helligkeit * 0.5
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            if now.hour < 5 and not status["dimmen"]:
 | 
					 | 
					 | 
					 | 
					            if now.hour < 5 and not status["dimmen"]:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                helligkeit = 0
 | 
					 | 
					 | 
					 | 
					                helligkeit = 0
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            uhr.set_helligkeit(helligkeit)
 | 
					 | 
					 | 
					 | 
					            uhr.set_helligkeit(helligkeit)
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -192,11 +217,14 @@ def main():
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    rgbconf = rgb_standard()
 | 
					 | 
					 | 
					 | 
					    rgbconf = rgb_standard()
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    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)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    uhr = Uhr(pixels)
 | 
					 | 
					 | 
					 | 
					    uhr = Uhr(pixels)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    thread_check_wlan = threading.Thread(target=check_anwesenheit, args=(uhr,))
 | 
					 | 
					 | 
					 | 
					    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)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    I_PLUS_TASTER.when_pressed = uhr.helligkeit_erhoehen
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    I_MINUS_TASTER.when_pressed = uhr.helligkeit_verringern
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    try:
 | 
					 | 
					 | 
					 | 
					    try:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        while True:
 | 
					 | 
					 | 
					 | 
					        while True:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            rgbconf = rgb_standard()
 | 
					 | 
					 | 
					 | 
					            rgbconf = rgb_standard()
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
 
 |