diff options
Diffstat (limited to 'main/tollgate_main.c')
| -rw-r--r-- | main/tollgate_main.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/main/tollgate_main.c b/main/tollgate_main.c index 1350d70..ad5211a 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"; |
| @@ -54,6 +56,7 @@ static void wifi_event_handler(void *arg, esp_event_base_t event_base, | |||
| 54 | tollgate_client_on_sta_disconnected(); | 56 | tollgate_client_on_sta_disconnected(); |
| 55 | if (s_services_running) stop_services(); | 57 | if (s_services_running) stop_services(); |
| 56 | if (s_retry_count < MAX_STA_RETRY) { | 58 | if (s_retry_count < MAX_STA_RETRY) { |
| 59 | vTaskDelay(pdMS_TO_TICKS(2000)); | ||
| 57 | esp_wifi_connect(); | 60 | esp_wifi_connect(); |
| 58 | } else { | 61 | } else { |
| 59 | wifi_config_t wifi_cfg; | 62 | wifi_config_t wifi_cfg; |
| @@ -94,6 +97,13 @@ static void ip_event_handler(void *arg, esp_event_base_t event_base, | |||
| 94 | s_retry_count = 0; | 97 | s_retry_count = 0; |
| 95 | xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); | 98 | xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); |
| 96 | 99 | ||
| 100 | esp_sntp_stop(); | ||
| 101 | esp_sntp_setoperatingmode(SNTP_OPMODE_POLL); | ||
| 102 | esp_sntp_setservername(0, "pool.ntp.org"); | ||
| 103 | esp_sntp_setservername(1, "time.google.com"); | ||
| 104 | esp_sntp_init(); | ||
| 105 | ESP_LOGI(TAG, "SNTP time sync started"); | ||
| 106 | |||
| 97 | char gw_ip_str[16]; | 107 | char gw_ip_str[16]; |
| 98 | snprintf(gw_ip_str, sizeof(gw_ip_str), IPSTR, IP2STR(&event->ip_info.gw)); | 108 | snprintf(gw_ip_str, sizeof(gw_ip_str), IPSTR, IP2STR(&event->ip_info.gw)); |
| 99 | tollgate_client_on_sta_connected(gw_ip_str); | 109 | tollgate_client_on_sta_connected(gw_ip_str); |
| @@ -160,6 +170,11 @@ static void start_services(void) | |||
| 160 | s_services_running = true; | 170 | s_services_running = true; |
| 161 | if (s_services_mutex) xSemaphoreGive(s_services_mutex); | 171 | if (s_services_mutex) xSemaphoreGive(s_services_mutex); |
| 162 | ESP_LOGI(TAG, "=== TollGate services started ==="); | 172 | ESP_LOGI(TAG, "=== TollGate services started ==="); |
| 173 | |||
| 174 | display_set_state(DISPLAY_READY); | ||
| 175 | char portal_url[128]; | ||
| 176 | snprintf(portal_url, sizeof(portal_url), "http://%s/", cfg->ap_ip_str); | ||
| 177 | display_update(cfg->ap_ssid, 0, 0, portal_url); | ||
| 163 | } | 178 | } |
| 164 | 179 | ||
| 165 | static void stop_services(void) | 180 | static void stop_services(void) |
| @@ -240,6 +255,9 @@ void app_main(void) | |||
| 240 | { | 255 | { |
| 241 | ESP_LOGI(TAG, "=== TollGate ESP32 Starting ==="); | 256 | ESP_LOGI(TAG, "=== TollGate ESP32 Starting ==="); |
| 242 | 257 | ||
| 258 | display_init(); | ||
| 259 | display_set_state(DISPLAY_BOOT); | ||
| 260 | |||
| 243 | esp_err_t ret = nvs_flash_init(); | 261 | esp_err_t ret = nvs_flash_init(); |
| 244 | if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { | 262 | if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { |
| 245 | ESP_ERROR_CHECK(nvs_flash_erase()); | 263 | ESP_ERROR_CHECK(nvs_flash_erase()); |
| @@ -288,6 +306,9 @@ void app_main(void) | |||
| 288 | ESP_LOGI(TAG, "STA configured for SSID: %s", tcfg2->networks[tcfg2->current_network].ssid); | 306 | ESP_LOGI(TAG, "STA configured for SSID: %s", tcfg2->networks[tcfg2->current_network].ssid); |
| 289 | } | 307 | } |
| 290 | 308 | ||
| 309 | ESP_ERROR_CHECK(esp_wifi_set_country_code("DE", false)); | ||
| 310 | ESP_LOGI(TAG, "WiFi country code set to DE (EU regulatory domain)"); | ||
| 311 | |||
| 291 | ESP_ERROR_CHECK(esp_wifi_start()); | 312 | ESP_ERROR_CHECK(esp_wifi_start()); |
| 292 | 313 | ||
| 293 | ESP_LOGI(TAG, "WiFi AP+STA started, waiting for connection..."); | 314 | ESP_LOGI(TAG, "WiFi AP+STA started, waiting for connection..."); |