Parse sync response from server

This commit is contained in:
2024-09-28 16:35:05 +02:00
parent 5704f2b57f
commit 58abf4ec9b
10 changed files with 205 additions and 23 deletions

@ -21,6 +21,8 @@ void app_main(void)
ESP_LOGI(TAG, "SolarEnergy WT32-ETH01 device");
// TODO : turn off all relays
// Initialize storage
if (storage_init() == false)
{
@ -167,22 +169,40 @@ void app_main(void)
// Main loop
ESP_LOGI(TAG, "Starting main loop");
// TODO : implement more properly
size_t fails = 0;
while (true)
{
if (!secure_api_sync_device())
sync_response *res = secure_api_sync_device();
if (!res)
{
fails += 1;
ESP_LOGE(TAG, "Failed to synchronise device!");
}
else
{
ESP_LOGI(TAG, "Successfully synchronised device!");
// Safely turn off all relays after a given number of failures
if (fails > 5)
{
ESP_LOGE(TAG, "Many failures, will stop all relays...");
// TODO : turn off all relays
}
// Restart the card after too much failures
if (fails > 10)
{
ESP_LOGE(TAG, "Too many failures, will try to reboot in 3 secs...");
system_sleep(3);
reboot();
}
system_sleep(SYNC_TIME_INTERVAL);
continue;
}
system_sleep(10);
// TODO : apply sync
sync_response_print(res);
sync_response_free(res);
system_sleep(SYNC_TIME_INTERVAL);
}
system_sleep(120);
reboot();
}