diff options
Diffstat (limited to 'main/tollgate_main.c')
| -rw-r--r-- | main/tollgate_main.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/main/tollgate_main.c b/main/tollgate_main.c index 1350d70..c0ff65f 100644 --- a/main/tollgate_main.c +++ b/main/tollgate_main.c | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include "esp_netif.h" | 9 | #include "esp_netif.h" |
| 10 | #include "lwip/netif.h" | 10 | #include "lwip/netif.h" |
| 11 | #include "lwip/dns.h" | 11 | #include "lwip/dns.h" |
| 12 | #include "esp_sntp.h" | ||
| 12 | #include "dhcpserver/dhcpserver.h" | 13 | #include "dhcpserver/dhcpserver.h" |
| 13 | #include "config.h" | 14 | #include "config.h" |
| 14 | #include "identity.h" | 15 | #include "identity.h" |
| @@ -22,6 +23,7 @@ | |||
| 22 | #include "tollgate_client.h" | 23 | #include "tollgate_client.h" |
| 23 | #include "lightning_payout.h" | 24 | #include "lightning_payout.h" |
| 24 | #include "cvm_server.h" | 25 | #include "cvm_server.h" |
| 26 | #include "display.h" | ||
| 25 | 27 | ||
| 26 | #define MAX_STA_RETRY 5 | 28 | #define MAX_STA_RETRY 5 |
| 27 | static const char *TAG = "tollgate_main"; | 29 | static const char *TAG = "tollgate_main"; |
| @@ -94,6 +96,13 @@ static void ip_event_handler(void *arg, esp_event_base_t event_base, | |||
| 94 | s_retry_count = 0; | 96 | s_retry_count = 0; |
| 95 | xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); | 97 | xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); |
| 96 | 98 | ||
| 99 | esp_sntp_stop(); | ||
| 100 | esp_sntp_setoperatingmode(SNTP_OPMODE_POLL); | ||
| 101 | esp_sntp_setservername(0, "pool.ntp.org"); | ||
| 102 | esp_sntp_setservername(1, "time.google.com"); | ||
| 103 | esp_sntp_init(); | ||
| 104 | ESP_LOGI(TAG, "SNTP time sync started"); | ||
| 105 | |||
| 97 | char gw_ip_str[16]; | 106 | char gw_ip_str[16]; |
| 98 | snprintf(gw_ip_str, sizeof(gw_ip_str), IPSTR, IP2STR(&event->ip_info.gw)); | 107 | snprintf(gw_ip_str, sizeof(gw_ip_str), IPSTR, IP2STR(&event->ip_info.gw)); |
| 99 | tollgate_client_on_sta_connected(gw_ip_str); | 108 | tollgate_client_on_sta_connected(gw_ip_str); |
| @@ -160,6 +169,11 @@ static void start_services(void) | |||
| 160 | s_services_running = true; | 169 | s_services_running = true; |
| 161 | if (s_services_mutex) xSemaphoreGive(s_services_mutex); | 170 | if (s_services_mutex) xSemaphoreGive(s_services_mutex); |
| 162 | ESP_LOGI(TAG, "=== TollGate services started ==="); | 171 | ESP_LOGI(TAG, "=== TollGate services started ==="); |
| 172 | |||
| 173 | display_set_state(DISPLAY_READY); | ||
| 174 | char portal_url[128]; | ||
| 175 | snprintf(portal_url, sizeof(portal_url), "http://%s/", cfg->ap_ip_str); | ||
| 176 | display_update(cfg->ap_ssid, 0, 0, portal_url); | ||
| 163 | } | 177 | } |
| 164 | 178 | ||
| 165 | static void stop_services(void) | 179 | static void stop_services(void) |
| @@ -240,6 +254,9 @@ void app_main(void) | |||
| 240 | { | 254 | { |
| 241 | ESP_LOGI(TAG, "=== TollGate ESP32 Starting ==="); | 255 | ESP_LOGI(TAG, "=== TollGate ESP32 Starting ==="); |
| 242 | 256 | ||
| 257 | display_init(); | ||
| 258 | display_set_state(DISPLAY_BOOT); | ||
| 259 | |||
| 243 | esp_err_t ret = nvs_flash_init(); | 260 | esp_err_t ret = nvs_flash_init(); |
| 244 | if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { | 261 | if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { |
| 245 | ESP_ERROR_CHECK(nvs_flash_erase()); | 262 | ESP_ERROR_CHECK(nvs_flash_erase()); |