pi server realised

This commit is contained in:
2026-02-15 12:57:05 +09:00
parent 89f75c23ef
commit 9ca0227214
7 changed files with 197 additions and 1 deletions

View File

@@ -97,6 +97,30 @@ static void parse_stats_json(const char *data, int len)
}
}
/* Parse local_time object for RTC sync */
cJSON *lt = cJSON_GetObjectItem(root, "local_time");
if (cJSON_IsObject(lt)) {
cJSON *y = cJSON_GetObjectItem(lt, "y");
cJSON *mo = cJSON_GetObjectItem(lt, "mo");
cJSON *d = cJSON_GetObjectItem(lt, "d");
cJSON *h = cJSON_GetObjectItem(lt, "h");
cJSON *m = cJSON_GetObjectItem(lt, "m");
cJSON *s = cJSON_GetObjectItem(lt, "s");
if (y && mo && d && h && m && s) {
s_stats.time_year = (uint16_t)y->valuedouble;
s_stats.time_month = (uint8_t)mo->valuedouble;
s_stats.time_day = (uint8_t)d->valuedouble;
s_stats.time_hour = (uint8_t)h->valuedouble;
s_stats.time_minute = (uint8_t)m->valuedouble;
s_stats.time_second = (uint8_t)s->valuedouble;
s_stats.time_valid = true;
} else {
s_stats.time_valid = false;
}
} else {
s_stats.time_valid = false;
}
s_stats.valid = true;
xSemaphoreGive(s_stats_mutex);

View File

@@ -36,6 +36,15 @@ typedef struct {
uint8_t service_count;
uint32_t last_update; // timestamp from server
bool valid; // set true after first successful parse
/* Broken-down local time from Pi for RTC sync */
uint16_t time_year;
uint8_t time_month;
uint8_t time_day;
uint8_t time_hour;
uint8_t time_minute;
uint8_t time_second;
bool time_valid; // true when local_time object was parsed
} pi_stats_t;
typedef void (*ws_data_callback_t)(const pi_stats_t *stats);