🚧 Adds checking and reconnecting when wlan is down
All checks were successful
Gitea Build Action / build (push) Successful in 24s
All checks were successful
Gitea Build Action / build (push) Successful in 24s
This commit is contained in:
parent
995bf90efb
commit
307b467ac1
@ -17,6 +17,7 @@ class App:
|
|||||||
|
|
||||||
opened: bool = False
|
opened: bool = False
|
||||||
previously_opened: bool = False
|
previously_opened: bool = False
|
||||||
|
wlan: network.WLAN
|
||||||
|
|
||||||
led = Pin(15, Pin.OUT)
|
led = Pin(15, Pin.OUT)
|
||||||
trigger = Pin(2, Pin.OUT)
|
trigger = Pin(2, Pin.OUT)
|
||||||
@ -55,18 +56,18 @@ class App:
|
|||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
print("Connecting to Wi-Fi...")
|
print("Connecting to Wi-Fi...")
|
||||||
wlan = network.WLAN(network.STA_IF)
|
self.wlan = network.WLAN(network.STA_IF)
|
||||||
|
|
||||||
wlan.active(False)
|
self.wlan.active(False)
|
||||||
utime.sleep_ms(250)
|
utime.sleep_ms(250)
|
||||||
wlan.active(True)
|
self.wlan.active(True)
|
||||||
utime.sleep_ms(250)
|
utime.sleep_ms(250)
|
||||||
|
|
||||||
wlan.connect(self.ssid, self.password)
|
self.wlan.connect(self.ssid, self.password)
|
||||||
utime.sleep_ms(100)
|
utime.sleep_ms(100)
|
||||||
|
|
||||||
retry_count = 0
|
retry_count = 0
|
||||||
while not wlan.isconnected():
|
while not self.wlan.isconnected():
|
||||||
if retry_count >= MAX_CONNECTION_RETRIES:
|
if retry_count >= MAX_CONNECTION_RETRIES:
|
||||||
print("Max connection retries reached")
|
print("Max connection retries reached")
|
||||||
exit(1)
|
exit(1)
|
||||||
@ -80,12 +81,12 @@ class App:
|
|||||||
|
|
||||||
if retry_count % 10 == 0:
|
if retry_count % 10 == 0:
|
||||||
print("Attempting to restart connection...")
|
print("Attempting to restart connection...")
|
||||||
wlan.connect(self.ssid, self.password)
|
self.wlan.connect(self.ssid, self.password)
|
||||||
for _ in range(10):
|
for _ in range(10):
|
||||||
self.led.toggle()
|
self.led.toggle()
|
||||||
utime.sleep_ms(50)
|
utime.sleep_ms(50)
|
||||||
|
|
||||||
print(f"Connected with IP {wlan.ifconfig()[0]}")
|
print(f"Connected with IP {self.wlan.ifconfig()[0]}")
|
||||||
self.update_server()
|
self.update_server()
|
||||||
|
|
||||||
def health_check_server(self):
|
def health_check_server(self):
|
||||||
@ -139,6 +140,9 @@ class App:
|
|||||||
i = 0
|
i = 0
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
if not self.wlan.isconnected():
|
||||||
|
self.connect()
|
||||||
|
|
||||||
distance = self.measure_distance()
|
distance = self.measure_distance()
|
||||||
self.opened = distance >= THRESHOLD_DISTANCE
|
self.opened = distance >= THRESHOLD_DISTANCE
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user