Compare commits

...

1 commit

Author SHA1 Message Date
82146efb03 fetch current time via NTP
Some checks failed
continuous-integration/drone/push Build is failing
2023-02-12 12:02:51 +01:00
4 changed files with 29 additions and 8 deletions

View file

@ -1,18 +1,17 @@
#include <FreeRTOS.h>
#include <task.h>
#include <esp/uart.h>
#include <espressif/esp_common.h>
#include "system.h" #include "system.h"
#include "wifi.h" #include "wifi.h"
#include "web.h" #include "web.h"
#include "mqtt.h" #include "mqtt.h"
#include "lux.h" #include "lux.h"
#include <stdio.h>
#include <FreeRTOS.h>
#include <task.h>
#include <espressif/esp_common.h>
#include <esp/uart.h>
void user_init(void) void user_init(void) {
{
uart_set_baud(0, 115200); uart_set_baud(0, 115200);
printf("SDK version: %s\n", sdk_system_get_sdk_version()); printf("SDK version: %s\n", sdk_system_get_sdk_version());
@ -27,4 +26,6 @@ void user_init(void)
xTaskCreate(&httpd_task, "httpd_task", 1024, NULL, 2, NULL); xTaskCreate(&httpd_task, "httpd_task", 1024, NULL, 2, NULL);
xTaskCreate(&lux_task, "lux_task", 512, NULL, 1, NULL); xTaskCreate(&lux_task, "lux_task", 512, NULL, 1, NULL);
xTaskCreate(&sntp_task, "sntp_task", 512, NULL, 2, NULL);
} }

View file

@ -10,7 +10,6 @@
#include <sysparam.h> #include <sysparam.h>
#include <spiflash.h> #include <spiflash.h>
#include <espressif/user_interface.h>
#include <espressif/esp_system.h> #include <espressif/esp_system.h>
#include <rboot/rboot.h> #include <rboot/rboot.h>
#include <rboot-ota/rboot-api.h> #include <rboot-ota/rboot-api.h>

View file

@ -10,11 +10,13 @@
#include <FreeRTOS.h> #include <FreeRTOS.h>
#include <task.h> #include <task.h>
#include <sockets.h> #include <sockets.h>
#include <time.h>
extern "C" { extern "C" {
#include <sysparam.h> #include <sysparam.h>
#include <lwipopts.h> #include <lwipopts.h>
#include <espressif/user_interface.h> #include <espressif/user_interface.h>
#include <sntp.h>
} }
#include <espressif/esp_wifi.h> #include <espressif/esp_wifi.h>
@ -357,5 +359,22 @@ extern "C" void wifi_task(void *pvParameters) {
xSemaphoreGive(wifi_available_semaphore); xSemaphoreGive(wifi_available_semaphore);
//monitor loop connection here //monitor loop connection here
vTaskDelete(nullptr);
}
const char *servers[] = {"0.pool.ntp.org", "1.pool.ntp.org", "2.pool.ntp.org", "3.pool.ntp.org"};
const struct timezone tz = {1 * 60, DST_NONE}; // DST_MET would actually be correct, but the SDK has a bug and doesn't handle it correctly
extern "C" void sntp_task(void *pvParameters) {
(void) pvParameters;
while (sdk_wifi_station_get_connect_status() != STATION_GOT_IP) {
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
sntp_set_update_delay(5 * 60000);
sntp_initialize(&tz);
sntp_set_servers(servers, sizeof(servers) / sizeof(char *));
vTaskDelete(nullptr); vTaskDelete(nullptr);
} }

View file

@ -16,6 +16,8 @@ extern SemaphoreHandle_t wifi_available_semaphore;
void wifi_task(void *pvParameters); void wifi_task(void *pvParameters);
void sntp_task(void *pvParameters);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif