hope it cannot be worse

This commit is contained in:
PoliEcho 2025-09-12 19:11:12 +02:00
parent 8b37490e88
commit b0f2f1611f

View File

@ -45,12 +45,16 @@ static char buffer[1024];
static err_t connected_callback(void *arg, struct tcp_pcb *tpcb, err_t err) {
if (err == ERR_OK) {
printf("Connected to server successfully!\n");
tcp_write(tpcb, timezone_request, strlen(timezone_request), TCP_WRITE_FLAG_COPY);
tcp_output(tpcb);
} else {
printf("Connection failed with error: %d\n", err);
request_error = true;
}
return ERR_OK;
}
err_t set_timezone_offset(void *arg, struct altcp_pcb *conn, struct pbuf *p,
err_t err) {
printf("\ncontent err %d\n", err);
@ -124,17 +128,15 @@ std::tuple<u16_t, err_t> get_timezone_offset() {
tcp_arg(pcb, &offset);
// ONLY initiate connection - do NOT send data here
if (tcp_connect(pcb, &timezone_server_ip, 80, connected_callback) == ERR_OK) {
tcp_write(pcb, timezone_request, strlen(timezone_request),
TCP_WRITE_FLAG_COPY);
tcp_output(pcb);
// Wait until request completes or errors out
uint32_t timeout_ms = 10000; // 10 second timeout
uint32_t timeout_ms = 10000;
uint32_t elapsed_ms = 0;
const uint32_t poll_interval = 100; // Check every 100ms
const uint32_t poll_interval = 50;
while (!request_complete && !request_error && elapsed_ms < timeout_ms) {
cyw43_arch_poll(); // Critical: Give lwIP time to process packets
sleep_ms(poll_interval);
elapsed_ms += poll_interval;
}
@ -157,6 +159,7 @@ std::tuple<u16_t, err_t> get_timezone_offset() {
return {offset, ERR_OK};
}
extern "C" void sync_system_time(unsigned int sec, unsigned int usec) {
printf("SNTP callback received: %lu\n", (unsigned long)sec);
time_t unix_time = (time_t)sec;