🐛 Fixes cannot update state
All checks were successful
Gitea Build Action / build (push) Successful in 29s

This commit is contained in:
Daniel Svitan 2025-06-01 12:30:42 +02:00
parent 329253b1f4
commit 2f3ccf14db
4 changed files with 15 additions and 3 deletions

1
.gitignore vendored
View File

@ -104,3 +104,4 @@ flake.lock
# Before adding new lines, see the comment at the top.
.env*
.idea/

View File

@ -1 +1,3 @@
__pycache__/
.env.json

View File

@ -90,6 +90,14 @@ class App:
print(f"Connected with IP {wlan.ifconfig()[0]}")
self.update_server()
def health_check_server(self):
print("Health checking server...", end="\r")
try:
r = urequests.get(f"{self.server}/")
print(f"Server healthy [{r.status_code}]{" " * 8}")
except Exception as e:
print(f"Error occurred: {e}")
def update_server(self):
print("Updating state...", end="\r")
data = {"opened": self.opened}
@ -101,7 +109,7 @@ class App:
headers={"Authorization": self.token, "Content-Type": "application/json"},
data=raw
)
print(f"State updated [{r.status_code}]")
print(f"State updated [{r.status_code}] {r.content.decode()}")
except Exception as e:
print(f"Error occurred: {e}")
@ -136,7 +144,7 @@ class App:
distance = self.measure_distance()
self.opened = distance >= THRESHOLD_DISTANCE
if not opened:
if not self.opened:
self.led.low()
self.ultra_opened_counter = 0
@ -154,7 +162,9 @@ class App:
utime.sleep_ms(100)
self.led.toggle()
utime.sleep_ms(400)
i = 0
self.health_check_server()
else:
utime.sleep_ms(500)

View File

@ -130,7 +130,6 @@ func main() {
}
if data.Opened == opened {
mut.Unlock()
return c.NoContent(http.StatusOK)
}