diff --git a/LED.py b/LED.py index 4dac0dd..ea42700 100644 --- a/LED.py +++ b/LED.py @@ -30,6 +30,8 @@ class LED(): toWait = min(50,blinkWaitMs) await asyncio.sleep_ms(toWait) waited += toWait + if self.blinkRate == None: + break blinkWaitMs = int(500 / self.blinkRate) def toggle(self): diff --git a/Screens.py b/Screens.py index 1f7bef5..862f73b 100644 --- a/Screens.py +++ b/Screens.py @@ -93,6 +93,7 @@ class InitHandsScreen(): HW.stepperminu.rotateTo(0) HW.stepperhour.rotateTo(0) HW.housingLEDs.upper((50,50,50)) + HW.leds[1].setOffState(pwmDuty=500,blinkRate=1.2) timeScreen = Get2PositionsScreen(\ startTime=(0,0),\ onStart=lambda _: HW.buzzer.playSound(HW.Buzzer.BEEP),\ @@ -102,6 +103,7 @@ class InitHandsScreen(): HW.stepperhour.reset() # Set the new Zero HW.stepperminu.reset() HW.housingLEDs.fill((0,0,0)) + HW.leds[1].setOffState() class SetAlarmTimeScreen(): def setAlarmTime(self,selectedTime): @@ -247,7 +249,6 @@ class Get2PositionsScreen(): self.mode=0 # 0: Minutes, 1: Hours HW.stepperminu.rotateTo(-(self.pickedTime[1])/12) HW.stepperhour.rotateTo(-(self.pickedTime[0])/12) - HW.leds[1].setOffState(blinkRate=1.2) for number,button in enumerate(HW.buttons): button.setCallbacks(\ onPushDown=lambda i=number:self.onButtonPressed(i),\ @@ -261,7 +262,6 @@ class Get2PositionsScreen(): await asyncio.sleep_ms(200) if self.onPicked: self.onPicked(self.pickedTime) - HW.leds[1].setOnState() # Reset to default __iter__ = __await__ # https://github.com/micropython/micropython/issues/2678 def finish(self): diff --git a/boot.py b/boot.py index a6974b0..0ad4f18 100644 --- a/boot.py +++ b/boot.py @@ -1,24 +1,47 @@ import network import webrepl +import uasyncio as asyncio + + +loop = asyncio.get_event_loop() webrepl.start() sta_if = network.WLAN(network.STA_IF) sta_if.active(True) -sta_if.config(dhcp_hostname="stepper-clock") +sta_if.config(dhcp_hostname="stepper-wecker") -if sta_if.status() != network.STAT_GOT_IP: - availableNetworkSSIDs = [s[0].decode() for s in sta_if.scan()] - print(availableNetworkSSIDs) - #load wifi credentials from file - with open("wifi-credentials","r") as f: - while sta_if.status() != network.STAT_GOT_IP: - ssid = f.readline() - password = f.readline()# - if not ssid or not password: - break - ssid = ssid.replace("\n","") - password = password.replace("\n","") - if ssid in availableNetworkSSIDs: - print("Connecting to",ssid) - sta_if.connect(ssid,password) - break \ No newline at end of file +async def connect(): + connectingFor = 0 + while True: + if sta_if.status() != network.STAT_GOT_IP: + if connectingFor > 5: + sta_if.disconnect() + connectingFor = 0 + else: + connectingFor += 1 + try: + availableNetworkSSIDs = [s[0].decode() for s in sta_if.scan()] + if len(availableNetworkSSIDs) > 0: + print("availableNetworkSSIDs:\n",availableNetworkSSIDs) + #load wifi credentials from file + with open("wifi-credentials","r") as f: + while sta_if.status() != network.STAT_GOT_IP: + ssid = f.readline() + password = f.readline()# + if not ssid or not password: + break + ssid = ssid.replace("\n","") + password = password.replace("\n","") + if ssid in availableNetworkSSIDs: + print("Connecting to",ssid) + sta_if.connect(ssid,password) + break + except: + pass + finally: + await asyncio.sleep(2) + else: + connectingFor = 0 + await asyncio.sleep(2) + +loop.create_task(connect()) \ No newline at end of file