🐛 Fixes cannot update state
All checks were successful
Gitea Build Action / build (push) Successful in 29s
All checks were successful
Gitea Build Action / build (push) Successful in 29s
This commit is contained in:
parent
329253b1f4
commit
2f3ccf14db
1
.gitignore
vendored
1
.gitignore
vendored
@ -104,3 +104,4 @@ flake.lock
|
|||||||
# Before adding new lines, see the comment at the top.
|
# Before adding new lines, see the comment at the top.
|
||||||
|
|
||||||
.env*
|
.env*
|
||||||
|
.idea/
|
||||||
|
2
peripheral/.gitignore
vendored
2
peripheral/.gitignore
vendored
@ -1 +1,3 @@
|
|||||||
|
__pycache__/
|
||||||
|
|
||||||
.env.json
|
.env.json
|
||||||
|
@ -90,6 +90,14 @@ class App:
|
|||||||
print(f"Connected with IP {wlan.ifconfig()[0]}")
|
print(f"Connected with IP {wlan.ifconfig()[0]}")
|
||||||
self.update_server()
|
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):
|
def update_server(self):
|
||||||
print("Updating state...", end="\r")
|
print("Updating state...", end="\r")
|
||||||
data = {"opened": self.opened}
|
data = {"opened": self.opened}
|
||||||
@ -101,7 +109,7 @@ class App:
|
|||||||
headers={"Authorization": self.token, "Content-Type": "application/json"},
|
headers={"Authorization": self.token, "Content-Type": "application/json"},
|
||||||
data=raw
|
data=raw
|
||||||
)
|
)
|
||||||
print(f"State updated [{r.status_code}]")
|
print(f"State updated [{r.status_code}] {r.content.decode()}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error occurred: {e}")
|
print(f"Error occurred: {e}")
|
||||||
|
|
||||||
@ -136,7 +144,7 @@ class App:
|
|||||||
distance = self.measure_distance()
|
distance = self.measure_distance()
|
||||||
self.opened = distance >= THRESHOLD_DISTANCE
|
self.opened = distance >= THRESHOLD_DISTANCE
|
||||||
|
|
||||||
if not opened:
|
if not self.opened:
|
||||||
self.led.low()
|
self.led.low()
|
||||||
self.ultra_opened_counter = 0
|
self.ultra_opened_counter = 0
|
||||||
|
|
||||||
@ -154,7 +162,9 @@ class App:
|
|||||||
utime.sleep_ms(100)
|
utime.sleep_ms(100)
|
||||||
self.led.toggle()
|
self.led.toggle()
|
||||||
utime.sleep_ms(400)
|
utime.sleep_ms(400)
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
|
self.health_check_server()
|
||||||
else:
|
else:
|
||||||
utime.sleep_ms(500)
|
utime.sleep_ms(500)
|
||||||
|
|
||||||
|
@ -130,7 +130,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if data.Opened == opened {
|
if data.Opened == opened {
|
||||||
mut.Unlock()
|
|
||||||
return c.NoContent(http.StatusOK)
|
return c.NoContent(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user