Fix keyword argument decoding issue on MicroPython and finalize raw image endpoint and clock sync changes
This commit is contained in:
@@ -149,6 +149,33 @@ def stream_hermes_request(url, headers, filename):
|
||||
return status_code, resp_headers, s
|
||||
|
||||
|
||||
def sync_ntp_time(rtc_chip):
|
||||
if rtc_chip is None:
|
||||
return False
|
||||
import ntptime
|
||||
import wifi_config
|
||||
|
||||
tz_offset = getattr(wifi_config, 'TZ_OFFSET', 0)
|
||||
print(f"Syncing time from NTP server... (Timezone offset: {tz_offset} hours)")
|
||||
|
||||
for attempt in range(3):
|
||||
try:
|
||||
utc_sec = ntptime.time()
|
||||
local_sec = utc_sec + int(tz_offset * 3600)
|
||||
t = time.localtime(local_sec)
|
||||
|
||||
dt = (t[0], t[1], t[2], t[6], t[3], t[4], t[5])
|
||||
rtc_chip.set_datetime(dt)
|
||||
rtc_chip.sync_to_system()
|
||||
t_str = f"{t[0]:04d}-{t[1]:02d}-{t[2]:02d} {t[3]:02d}:{t[4]:02d}:{t[5]:02d}"
|
||||
print(f"Successfully synced RTC with NTP. Local time: {t_str}")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"NTP sync attempt {attempt+1} failed: {e}")
|
||||
time.sleep_ms(200)
|
||||
return False
|
||||
|
||||
|
||||
# LED mode options for manual cycling
|
||||
led_modes = [
|
||||
("Red (Breathing)", lambda led: led.set_color(40, 0, 0), "breath"),
|
||||
@@ -240,6 +267,9 @@ def main():
|
||||
from mcp_server import MCPServer
|
||||
mcp = MCPServer(display, led, battery, sensor, rtc_chip, ble_uart, vstream=vstream, touch=touch)
|
||||
mcp.start(port=80)
|
||||
|
||||
if wlan.isconnected():
|
||||
sync_ntp_time(rtc_chip)
|
||||
except Exception as ne:
|
||||
print("Failed to start network services:", ne)
|
||||
|
||||
@@ -317,6 +347,7 @@ def main():
|
||||
print(f"Wi-Fi Connected! IP Address: {ip_addr}")
|
||||
last_action_str = f"Wi-Fi Connected: {ip_addr}"
|
||||
force_dashboard_redraw = True
|
||||
sync_ntp_time(rtc_chip)
|
||||
|
||||
# Check voice assistant trigger (touch screen or physical key button)
|
||||
if is_talk_trigger_active():
|
||||
@@ -497,7 +528,7 @@ def main():
|
||||
resp_text = ""
|
||||
if content_len > 0:
|
||||
try:
|
||||
resp_text = socket_read_exactly(s, content_len).decode('utf-8', errors='ignore')
|
||||
resp_text = socket_read_exactly(s, content_len).decode('utf-8', 'ignore')
|
||||
except:
|
||||
pass
|
||||
print("Non-WAV response received:", resp_text)
|
||||
@@ -511,7 +542,7 @@ def main():
|
||||
resp_text = "Unknown error"
|
||||
if content_len > 0:
|
||||
try:
|
||||
resp_text = socket_read_exactly(s, content_len).decode('utf-8', errors='ignore')
|
||||
resp_text = socket_read_exactly(s, content_len).decode('utf-8', 'ignore')
|
||||
except:
|
||||
pass
|
||||
print("Error response:", resp_text)
|
||||
|
||||
Reference in New Issue
Block a user