diff options
| author | Your Name <you@example.com> | 2026-05-21 06:20:45 +0530 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-05-21 06:20:45 +0530 |
| commit | 716daafce3eaa5ebfd246c1ef9915a2972b4c6fd (patch) | |
| tree | 79535bd62e66a82b248d96174b57a1c0f861cc2d /main | |
| parent | 60797e35dda136e08b0a6c966fa92107095e6e64 (diff) | |
fix: TLS allocation, stack overflow, DNS bind — mint now reachable
Root cause: mbedtls SSL buffers (16KB) couldn't allocate from fragmented
internal RAM (largest block 8KB). Fix by lowering SPIRAM_MALLOC_ALWAYSINTERNAL
from 16KB to 4KB, allowing SSL buffers to go to PSRAM.
Additional fixes:
- DNS server binds to AP IP only (prevents self-hijacking)
- start_services() moved from esp_timer (2KB stack) to dedicated FreeRTOS
task (16KB stack) — was causing stack overflow with dynamic buffers
- Mint health probe now logs errors and exposes last_err in API
- Debug endpoint shows internal/PSRAM heap breakdown and DNS resolve test
- Enabled CONFIG_MBEDTLS_DYNAMIC_BUFFER for better memory management
- Board C config: mint_url → testnut-nutshell.mints.orangesync.tech
Diffstat (limited to 'main')
| -rw-r--r-- | main/dns_server.c | 2 | ||||
| -rw-r--r-- | main/mint_health.c | 19 | ||||
| -rw-r--r-- | main/mint_health.h | 1 | ||||
| -rw-r--r-- | main/tollgate_api.c | 47 | ||||
| -rw-r--r-- | main/tollgate_main.c | 66 |
5 files changed, 111 insertions, 24 deletions
diff --git a/main/dns_server.c b/main/dns_server.c index 15a729f..b84a4cf 100644 --- a/main/dns_server.c +++ b/main/dns_server.c | |||
| @@ -161,7 +161,7 @@ static void dns_server_task(void *arg) | |||
| 161 | struct sockaddr_in bind_addr = { | 161 | struct sockaddr_in bind_addr = { |
| 162 | .sin_family = AF_INET, | 162 | .sin_family = AF_INET, |
| 163 | .sin_port = htons(DNS_PORT), | 163 | .sin_port = htons(DNS_PORT), |
| 164 | .sin_addr.s_addr = INADDR_ANY, | 164 | .sin_addr.s_addr = s_ap_ip.addr, |
| 165 | }; | 165 | }; |
| 166 | if (bind(sock, (struct sockaddr *)&bind_addr, sizeof(bind_addr)) < 0) { | 166 | if (bind(sock, (struct sockaddr *)&bind_addr, sizeof(bind_addr)) < 0) { |
| 167 | ESP_LOGE(TAG, "Failed to bind DNS socket"); | 167 | ESP_LOGE(TAG, "Failed to bind DNS socket"); |
diff --git a/main/mint_health.c b/main/mint_health.c index 5853a39..26d73a6 100644 --- a/main/mint_health.c +++ b/main/mint_health.c | |||
| @@ -7,9 +7,12 @@ | |||
| 7 | #include "freertos/semphr.h" | 7 | #include "freertos/semphr.h" |
| 8 | #include <string.h> | 8 | #include <string.h> |
| 9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
| 10 | #include <errno.h> | ||
| 10 | 11 | ||
| 11 | static const char *TAG = "mint_health"; | 12 | static const char *TAG = "mint_health"; |
| 12 | 13 | ||
| 14 | static int s_last_probe_err = 0; | ||
| 15 | |||
| 13 | static mint_status_t s_mints[MINT_HEALTH_MAX]; | 16 | static mint_status_t s_mints[MINT_HEALTH_MAX]; |
| 14 | static int s_mint_count = 0; | 17 | static int s_mint_count = 0; |
| 15 | static bool s_running = false; | 18 | static bool s_running = false; |
| @@ -60,16 +63,26 @@ static bool probe_mint(const char *url) | |||
| 60 | .crt_bundle_attach = esp_crt_bundle_attach, | 63 | .crt_bundle_attach = esp_crt_bundle_attach, |
| 61 | }; | 64 | }; |
| 62 | esp_http_client_handle_t client = esp_http_client_init(&config); | 65 | esp_http_client_handle_t client = esp_http_client_init(&config); |
| 63 | if (!client) return false; | 66 | if (!client) { |
| 67 | ESP_LOGE(TAG, "probe: init failed for %s", probe_url); | ||
| 68 | s_last_probe_err = -1; | ||
| 69 | return false; | ||
| 70 | } | ||
| 64 | 71 | ||
| 65 | esp_err_t err = esp_http_client_open(client, 0); | 72 | esp_err_t err = esp_http_client_open(client, 0); |
| 66 | if (err != ESP_OK) { | 73 | if (err != ESP_OK) { |
| 74 | ESP_LOGE(TAG, "probe: open failed for %s err=0x%x", probe_url, err); | ||
| 75 | int sc = esp_http_client_get_status_code(client); | ||
| 76 | ESP_LOGE(TAG, "probe: status=%d errno=%d(%s)", sc, errno, strerror(errno)); | ||
| 77 | s_last_probe_err = err; | ||
| 67 | esp_http_client_cleanup(client); | 78 | esp_http_client_cleanup(client); |
| 68 | return false; | 79 | return false; |
| 69 | } | 80 | } |
| 70 | 81 | ||
| 71 | int content_length = esp_http_client_fetch_headers(client); | 82 | int content_length = esp_http_client_fetch_headers(client); |
| 72 | int status = esp_http_client_get_status_code(client); | 83 | int status = esp_http_client_get_status_code(client); |
| 84 | ESP_LOGI(TAG, "probe: %s -> status=%d len=%d", probe_url, status, content_length); | ||
| 85 | s_last_probe_err = 0; | ||
| 73 | 86 | ||
| 74 | char *resp = NULL; | 87 | char *resp = NULL; |
| 75 | if (content_length > 0 && content_length < 8192) { | 88 | if (content_length > 0 && content_length < 8192) { |
| @@ -100,6 +113,7 @@ static void run_probes(void) | |||
| 100 | bool ok = probe_mint(s_mints[i].url); | 113 | bool ok = probe_mint(s_mints[i].url); |
| 101 | s_mints[i].last_probe_ms = (int64_t)xTaskGetTickCount() * portTICK_PERIOD_MS; | 114 | s_mints[i].last_probe_ms = (int64_t)xTaskGetTickCount() * portTICK_PERIOD_MS; |
| 102 | s_mints[i].last_http_status = ok ? 200 : 0; | 115 | s_mints[i].last_http_status = ok ? 200 : 0; |
| 116 | s_mints[i].last_err = ok ? 0 : s_last_probe_err; | ||
| 103 | 117 | ||
| 104 | if (ok) { | 118 | if (ok) { |
| 105 | s_mints[i].consecutive_successes++; | 119 | s_mints[i].consecutive_successes++; |
| @@ -111,7 +125,7 @@ static void run_probes(void) | |||
| 111 | } | 125 | } |
| 112 | } else { | 126 | } else { |
| 113 | if (s_mints[i].reachable) { | 127 | if (s_mints[i].reachable) { |
| 114 | ESP_LOGW(TAG, "Mint UNREACHABLE: %s", s_mints[i].url); | 128 | ESP_LOGW(TAG, "Mint UNREACHABLE: %s err=0x%x", s_mints[i].url, s_last_probe_err); |
| 115 | } | 129 | } |
| 116 | s_mints[i].reachable = false; | 130 | s_mints[i].reachable = false; |
| 117 | s_mints[i].consecutive_successes = 0; | 131 | s_mints[i].consecutive_successes = 0; |
| @@ -137,6 +151,7 @@ static void run_initial_probes(void) | |||
| 137 | bool ok = probe_mint(s_mints[i].url); | 151 | bool ok = probe_mint(s_mints[i].url); |
| 138 | s_mints[i].last_probe_ms = (int64_t)xTaskGetTickCount() * portTICK_PERIOD_MS; | 152 | s_mints[i].last_probe_ms = (int64_t)xTaskGetTickCount() * portTICK_PERIOD_MS; |
| 139 | s_mints[i].last_http_status = ok ? 200 : 0; | 153 | s_mints[i].last_http_status = ok ? 200 : 0; |
| 154 | s_mints[i].last_err = ok ? 0 : s_last_probe_err; | ||
| 140 | 155 | ||
| 141 | if (ok) { | 156 | if (ok) { |
| 142 | s_mints[i].consecutive_successes = MINT_HEALTH_RECOVERY_THRESHOLD; | 157 | s_mints[i].consecutive_successes = MINT_HEALTH_RECOVERY_THRESHOLD; |
diff --git a/main/mint_health.h b/main/mint_health.h index f047d6a..33413db 100644 --- a/main/mint_health.h +++ b/main/mint_health.h | |||
| @@ -16,6 +16,7 @@ typedef struct { | |||
| 16 | uint8_t consecutive_successes; | 16 | uint8_t consecutive_successes; |
| 17 | int64_t last_probe_ms; | 17 | int64_t last_probe_ms; |
| 18 | int last_http_status; | 18 | int last_http_status; |
| 19 | int last_err; | ||
| 19 | } mint_status_t; | 20 | } mint_status_t; |
| 20 | 21 | ||
| 21 | typedef void (*mint_health_changed_cb)(void); | 22 | typedef void (*mint_health_changed_cb)(void); |
diff --git a/main/tollgate_api.c b/main/tollgate_api.c index af91093..5ac0543 100644 --- a/main/tollgate_api.c +++ b/main/tollgate_api.c | |||
| @@ -5,6 +5,11 @@ | |||
| 5 | #include "session.h" | 5 | #include "session.h" |
| 6 | #include "captive_portal.h" | 6 | #include "captive_portal.h" |
| 7 | #include "firewall.h" | 7 | #include "firewall.h" |
| 8 | #include "lwip/dns.h" | ||
| 9 | #include "lwip/netdb.h" | ||
| 10 | #include "esp_http_client.h" | ||
| 11 | #include "esp_crt_bundle.h" | ||
| 12 | #include "esp_heap_caps.h" | ||
| 8 | #include "nucula_wallet.h" | 13 | #include "nucula_wallet.h" |
| 9 | #include "mint_health.h" | 14 | #include "mint_health.h" |
| 10 | #include "market.h" | 15 | #include "market.h" |
| @@ -510,6 +515,12 @@ static esp_err_t api_get_mints(httpd_req_t *req) | |||
| 510 | cJSON *obj = cJSON_CreateObject(); | 515 | cJSON *obj = cJSON_CreateObject(); |
| 511 | cJSON_AddStringToObject(obj, "url", mints[i].url); | 516 | cJSON_AddStringToObject(obj, "url", mints[i].url); |
| 512 | cJSON_AddBoolToObject(obj, "reachable", mints[i].reachable); | 517 | cJSON_AddBoolToObject(obj, "reachable", mints[i].reachable); |
| 518 | cJSON_AddNumberToObject(obj, "status", mints[i].last_http_status); | ||
| 519 | if (mints[i].last_err) { | ||
| 520 | char errbuf[16]; | ||
| 521 | snprintf(errbuf, sizeof(errbuf), "0x%x", mints[i].last_err); | ||
| 522 | cJSON_AddStringToObject(obj, "last_err", errbuf); | ||
| 523 | } | ||
| 513 | cJSON_AddItemToArray(arr, obj); | 524 | cJSON_AddItemToArray(arr, obj); |
| 514 | } | 525 | } |
| 515 | char *json = cJSON_PrintUnformatted(arr); | 526 | char *json = cJSON_PrintUnformatted(arr); |
| @@ -686,6 +697,8 @@ extern bool s_start_services_called; | |||
| 686 | extern bool s_start_ap_services_called; | 697 | extern bool s_start_ap_services_called; |
| 687 | extern bool s_sta_got_ip; | 698 | extern bool s_sta_got_ip; |
| 688 | extern bool s_ap_started; | 699 | extern bool s_ap_started; |
| 700 | extern esp_ip4_addr_t s_sta_ip; | ||
| 701 | extern esp_ip4_addr_t s_sta_gw; | ||
| 689 | 702 | ||
| 690 | static esp_err_t api_get_debug(httpd_req_t *req) | 703 | static esp_err_t api_get_debug(httpd_req_t *req) |
| 691 | { | 704 | { |
| @@ -700,6 +713,40 @@ static esp_err_t api_get_debug(httpd_req_t *req) | |||
| 700 | cJSON_AddBoolToObject(root, "ap_started", s_ap_started); | 713 | cJSON_AddBoolToObject(root, "ap_started", s_ap_started); |
| 701 | cJSON_AddNumberToObject(root, "free_heap", (double)esp_get_free_heap_size()); | 714 | cJSON_AddNumberToObject(root, "free_heap", (double)esp_get_free_heap_size()); |
| 702 | cJSON_AddNumberToObject(root, "min_free_heap", (double)esp_get_minimum_free_heap_size()); | 715 | cJSON_AddNumberToObject(root, "min_free_heap", (double)esp_get_minimum_free_heap_size()); |
| 716 | cJSON_AddNumberToObject(root, "free_internal", (double)heap_caps_get_free_size(MALLOC_CAP_INTERNAL)); | ||
| 717 | cJSON_AddNumberToObject(root, "largest_internal", (double)heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL)); | ||
| 718 | cJSON_AddNumberToObject(root, "free_spiram", (double)heap_caps_get_free_size(MALLOC_CAP_SPIRAM)); | ||
| 719 | |||
| 720 | char dns0[16], dns1[16], dns2[16]; | ||
| 721 | const ip_addr_t *d0 = dns_getserver(0); | ||
| 722 | const ip_addr_t *d1 = dns_getserver(1); | ||
| 723 | const ip_addr_t *d2 = dns_getserver(2); | ||
| 724 | snprintf(dns0, sizeof(dns0), IPSTR, IP2STR(&(esp_ip4_addr_t){.addr=d0->addr})); | ||
| 725 | snprintf(dns1, sizeof(dns1), IPSTR, IP2STR(&(esp_ip4_addr_t){.addr=d1->addr})); | ||
| 726 | snprintf(dns2, sizeof(dns2), IPSTR, IP2STR(&(esp_ip4_addr_t){.addr=d2->addr})); | ||
| 727 | cJSON_AddStringToObject(root, "dns0", dns0); | ||
| 728 | cJSON_AddStringToObject(root, "dns1", dns1); | ||
| 729 | cJSON_AddStringToObject(root, "dns2", dns2); | ||
| 730 | |||
| 731 | char sta_ip_str[16], sta_gw_str[16]; | ||
| 732 | snprintf(sta_ip_str, sizeof(sta_ip_str), IPSTR, IP2STR(&s_sta_ip)); | ||
| 733 | snprintf(sta_gw_str, sizeof(sta_gw_str), IPSTR, IP2STR(&s_sta_gw)); | ||
| 734 | cJSON_AddStringToObject(root, "sta_ip", sta_ip_str); | ||
| 735 | cJSON_AddStringToObject(root, "sta_gw", sta_gw_str); | ||
| 736 | |||
| 737 | struct addrinfo hints = {0}, *res = NULL; | ||
| 738 | hints.ai_family = AF_INET; | ||
| 739 | int dns_rc = getaddrinfo("testnut-compat.mints.orangesync.tech", NULL, &hints, &res); | ||
| 740 | if (dns_rc == 0 && res) { | ||
| 741 | struct sockaddr_in *addr = (struct sockaddr_in *)res->ai_addr; | ||
| 742 | char resolved[16]; | ||
| 743 | snprintf(resolved, sizeof(resolved), IPSTR, IP2STR(&(esp_ip4_addr_t){.addr=addr->sin_addr.s_addr})); | ||
| 744 | cJSON_AddStringToObject(root, "dns_resolve", resolved); | ||
| 745 | } else { | ||
| 746 | cJSON_AddStringToObject(root, "dns_resolve", dns_rc == 0 ? "no-addr" : "FAIL"); | ||
| 747 | } | ||
| 748 | if (res) freeaddrinfo(res); | ||
| 749 | |||
| 703 | char *json = cJSON_PrintUnformatted(root); | 750 | char *json = cJSON_PrintUnformatted(root); |
| 704 | httpd_resp_set_type(req, "application/json"); | 751 | httpd_resp_set_type(req, "application/json"); |
| 705 | httpd_resp_sendstr(req, json); | 752 | httpd_resp_sendstr(req, json); |
diff --git a/main/tollgate_main.c b/main/tollgate_main.c index 23b4a00..ebfa52e 100644 --- a/main/tollgate_main.c +++ b/main/tollgate_main.c | |||
| @@ -8,7 +8,6 @@ | |||
| 8 | #include "esp_system.h" | 8 | #include "esp_system.h" |
| 9 | #include "nvs_flash.h" | 9 | #include "nvs_flash.h" |
| 10 | #include "esp_netif.h" | 10 | #include "esp_netif.h" |
| 11 | #include "esp_timer.h" | ||
| 12 | #include "lwip/netif.h" | 11 | #include "lwip/netif.h" |
| 13 | #include "lwip/dns.h" | 12 | #include "lwip/dns.h" |
| 14 | #include "esp_sntp.h" | 13 | #include "esp_sntp.h" |
| @@ -60,6 +59,8 @@ volatile bool s_start_services_called = false; | |||
| 60 | volatile bool s_start_ap_services_called = false; | 59 | volatile bool s_start_ap_services_called = false; |
| 61 | volatile bool s_sta_got_ip = false; | 60 | volatile bool s_sta_got_ip = false; |
| 62 | volatile bool s_ap_started = false; | 61 | volatile bool s_ap_started = false; |
| 62 | volatile esp_ip4_addr_t s_sta_ip = {0}; | ||
| 63 | volatile esp_ip4_addr_t s_sta_gw = {0}; | ||
| 63 | 64 | ||
| 64 | static void start_services(void); | 65 | static void start_services(void); |
| 65 | static void stop_services(void); | 66 | static void stop_services(void); |
| @@ -134,13 +135,12 @@ static void wifi_event_handler(void *arg, esp_event_base_t event_base, | |||
| 134 | } | 135 | } |
| 135 | } | 136 | } |
| 136 | 137 | ||
| 137 | static void services_start_timer_cb(void *arg) | 138 | static void services_start_task(void *pvParameters) |
| 138 | { | 139 | { |
| 139 | start_services(); | 140 | start_services(); |
| 141 | vTaskDelete(NULL); | ||
| 140 | } | 142 | } |
| 141 | 143 | ||
| 142 | static esp_timer_handle_t s_services_timer; | ||
| 143 | |||
| 144 | static void ip_event_handler(void *arg, esp_event_base_t event_base, | 144 | static void ip_event_handler(void *arg, esp_event_base_t event_base, |
| 145 | int32_t event_id, void *event_data) | 145 | int32_t event_id, void *event_data) |
| 146 | { | 146 | { |
| @@ -149,15 +149,15 @@ static void ip_event_handler(void *arg, esp_event_base_t event_base, | |||
| 149 | ESP_LOGI(TAG, "Got IP:" IPSTR ", GW:" IPSTR, IP2STR(&event->ip_info.ip), IP2STR(&event->ip_info.gw)); | 149 | ESP_LOGI(TAG, "Got IP:" IPSTR ", GW:" IPSTR, IP2STR(&event->ip_info.ip), IP2STR(&event->ip_info.gw)); |
| 150 | s_retry_count = 0; | 150 | s_retry_count = 0; |
| 151 | s_sta_got_ip = true; | 151 | s_sta_got_ip = true; |
| 152 | s_sta_ip.addr = event->ip_info.ip.addr; | ||
| 153 | s_sta_gw.addr = event->ip_info.gw.addr; | ||
| 152 | xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); | 154 | xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); |
| 153 | 155 | ||
| 154 | const esp_timer_create_args_t timer_cfg = { | 156 | static TaskHandle_t s_svc_task = NULL; |
| 155 | .callback = services_start_timer_cb, | 157 | if (s_svc_task == NULL) { |
| 156 | .name = "svc_start", | 158 | xTaskCreate(services_start_task, "svc_start", 16384, NULL, 5, &s_svc_task); |
| 157 | }; | 159 | ESP_LOGI(TAG, "services_start_task spawned (3s delay)"); |
| 158 | ESP_ERROR_CHECK(esp_timer_create(&timer_cfg, &s_services_timer)); | 160 | } |
| 159 | ESP_ERROR_CHECK(esp_timer_start_once(s_services_timer, 3000000)); | ||
| 160 | ESP_LOGI(TAG, "services_start_timer scheduled (3s)"); | ||
| 161 | 161 | ||
| 162 | esp_sntp_stop(); | 162 | esp_sntp_stop(); |
| 163 | esp_sntp_setoperatingmode(SNTP_OPMODE_POLL); | 163 | esp_sntp_setoperatingmode(SNTP_OPMODE_POLL); |
| @@ -187,6 +187,7 @@ static void publish_wifistr_task(void *pvParameters) | |||
| 187 | 187 | ||
| 188 | static void start_services(void) | 188 | static void start_services(void) |
| 189 | { | 189 | { |
| 190 | vTaskDelay(pdMS_TO_TICKS(3000)); | ||
| 190 | ESP_LOGI(TAG, ">>> start_services() called"); | 191 | ESP_LOGI(TAG, ">>> start_services() called"); |
| 191 | if (s_services_mutex) xSemaphoreTake(s_services_mutex, portMAX_DELAY); | 192 | if (s_services_mutex) xSemaphoreTake(s_services_mutex, portMAX_DELAY); |
| 192 | if (s_services_running) { | 193 | if (s_services_running) { |
| @@ -204,6 +205,34 @@ static void start_services(void) | |||
| 204 | const ip_addr_t *dns_addr = dns_getserver(0); | 205 | const ip_addr_t *dns_addr = dns_getserver(0); |
| 205 | upstream_dns.addr = dns_addr->addr; | 206 | upstream_dns.addr = dns_addr->addr; |
| 206 | 207 | ||
| 208 | if (upstream_dns.addr == ap_ip_info.ip.addr) { | ||
| 209 | ESP_LOGW(TAG, "DNS[0] is our own AP IP — trying DNS[1] and STA gateway"); | ||
| 210 | const ip_addr_t *dns1 = dns_getserver(1); | ||
| 211 | if (dns1->addr != 0 && dns1->addr != ap_ip_info.ip.addr) { | ||
| 212 | upstream_dns.addr = dns1->addr; | ||
| 213 | dns_setserver(0, dns1); | ||
| 214 | ESP_LOGI(TAG, "Fixed DNS[0] to " IPSTR " from DNS[1]", IP2STR(&upstream_dns)); | ||
| 215 | } else { | ||
| 216 | esp_netif_dns_info_t sta_dns; | ||
| 217 | if (esp_netif_get_dns_info(s_sta_netif, ESP_NETIF_DNS_MAIN, &sta_dns) == ESP_OK | ||
| 218 | && sta_dns.ip.u_addr.ip4.addr != 0 | ||
| 219 | && sta_dns.ip.u_addr.ip4.addr != ap_ip_info.ip.addr) { | ||
| 220 | upstream_dns.addr = sta_dns.ip.u_addr.ip4.addr; | ||
| 221 | ip_addr_t lwip_dns = {0}; | ||
| 222 | lwip_dns.addr = sta_dns.ip.u_addr.ip4.addr; | ||
| 223 | dns_setserver(0, &lwip_dns); | ||
| 224 | ESP_LOGI(TAG, "Fixed DNS[0] to " IPSTR " from STA netif", IP2STR(&upstream_dns)); | ||
| 225 | } else { | ||
| 226 | ESP_LOGE(TAG, "No valid upstream DNS found! Mint verification will fail."); | ||
| 227 | } | ||
| 228 | } | ||
| 229 | } | ||
| 230 | |||
| 231 | ESP_LOGI(TAG, "DNS config: [0]=" IPSTR " [1]=" IPSTR " [2]=" IPSTR, | ||
| 232 | IP2STR(&(esp_ip4_addr_t){.addr=dns_getserver(0)->addr}), | ||
| 233 | IP2STR(&(esp_ip4_addr_t){.addr=dns_getserver(1)->addr}), | ||
| 234 | IP2STR(&(esp_ip4_addr_t){.addr=dns_getserver(2)->addr})); | ||
| 235 | |||
| 207 | firewall_init(ap_ip_info.ip); | 236 | firewall_init(ap_ip_info.ip); |
| 208 | session_manager_init(); | 237 | session_manager_init(); |
| 209 | 238 | ||
| @@ -305,10 +334,10 @@ static void wifi_create_ap_netif(void) | |||
| 305 | { | 334 | { |
| 306 | s_ap_netif = esp_netif_create_default_wifi_ap(); | 335 | s_ap_netif = esp_netif_create_default_wifi_ap(); |
| 307 | 336 | ||
| 308 | const tollgate_config_t *cfg = tollgate_config_get(); | 337 | const tollgate_config_t *cfg = tollgate_config_get(); |
| 309 | esp_ip4_addr_t ap_ip = cfg->ap_ip; | 338 | esp_ip4_addr_t ap_ip = cfg->ap_ip; |
| 310 | esp_ip4_addr_t ap_gw = cfg->ap_ip; | 339 | esp_ip4_addr_t ap_gw = {0}; |
| 311 | esp_ip4_addr_t ap_mask; | 340 | esp_ip4_addr_t ap_mask; |
| 312 | IP4_ADDR(&ap_mask, 255, 255, 255, 0); | 341 | IP4_ADDR(&ap_mask, 255, 255, 255, 0); |
| 313 | 342 | ||
| 314 | strncpy(s_ap_ip_str, cfg->ap_ip_str, sizeof(s_ap_ip_str) - 1); | 343 | strncpy(s_ap_ip_str, cfg->ap_ip_str, sizeof(s_ap_ip_str) - 1); |
| @@ -425,12 +454,7 @@ void app_main(void) | |||
| 425 | 454 | ||
| 426 | if (tollgate_config_get_wifi(&(wifi_config_t){0}) != ESP_OK) { | 455 | if (tollgate_config_get_wifi(&(wifi_config_t){0}) != ESP_OK) { |
| 427 | ESP_LOGI(TAG, "No STA network configured, starting services immediately"); | 456 | ESP_LOGI(TAG, "No STA network configured, starting services immediately"); |
| 428 | const esp_timer_create_args_t timer_cfg = { | 457 | xTaskCreate(services_start_task, "svc_start_fb", 16384, NULL, 5, NULL); |
| 429 | .callback = services_start_timer_cb, | ||
| 430 | .name = "svc_start_fallback", | ||
| 431 | }; | ||
| 432 | ESP_ERROR_CHECK(esp_timer_create(&timer_cfg, &s_services_timer)); | ||
| 433 | ESP_ERROR_CHECK(esp_timer_start_once(s_services_timer, 3000000)); | ||
| 434 | } | 458 | } |
| 435 | 459 | ||
| 436 | while (1) { | 460 | while (1) { |