diff options
| author | Your Name <you@example.com> | 2026-05-20 02:18:36 +0530 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-05-20 02:18:36 +0530 |
| commit | f4f85f938405867be89cfee029d5117cb1b4ac69 (patch) | |
| tree | 3eeb8157410ead5a0ff17abc3551cfe09e778d50 /main | |
| parent | 899016795c389151e6b486ec470653f5688e5c5f (diff) | |
fix: resolve display-fix merge conflicts
- Update display_update() call to match new signature (7 args)
- Add tollgate_config_add_wifi() implementation for WiFi setup UI
Diffstat (limited to 'main')
| -rw-r--r-- | main/config.c | 52 | ||||
| -rw-r--r-- | main/tollgate_main.c | 2 |
2 files changed, 53 insertions, 1 deletions
diff --git a/main/config.c b/main/config.c index 43ab2a7..9d0d54c 100644 --- a/main/config.c +++ b/main/config.c | |||
| @@ -475,3 +475,55 @@ void tollgate_config_derive_unique(tollgate_config_t *cfg) | |||
| 475 | ESP_LOGI(TAG, "Unique config derived from nsec: SSID='%s', AP_IP=%s", | 475 | ESP_LOGI(TAG, "Unique config derived from nsec: SSID='%s', AP_IP=%s", |
| 476 | cfg->ap_ssid, cfg->ap_ip_str); | 476 | cfg->ap_ssid, cfg->ap_ip_str); |
| 477 | } | 477 | } |
| 478 | |||
| 479 | esp_err_t tollgate_config_add_wifi(const char *ssid, const char *password) { | ||
| 480 | if (!ssid || !password) return ESP_ERR_INVALID_ARG; | ||
| 481 | if (g_config.network_count >= TOLLGATE_MAX_WIFI_NETWORKS) return ESP_ERR_NO_MEM; | ||
| 482 | |||
| 483 | strncpy(g_config.networks[g_config.network_count].ssid, ssid, | ||
| 484 | sizeof(g_config.networks[g_config.network_count].ssid) - 1); | ||
| 485 | strncpy(g_config.networks[g_config.network_count].password, password, | ||
| 486 | sizeof(g_config.networks[g_config.network_count].password) - 1); | ||
| 487 | g_config.network_count++; | ||
| 488 | |||
| 489 | cJSON *root = cJSON_CreateObject(); | ||
| 490 | cJSON_AddStringToObject(root, "nsec", g_config.nsec); | ||
| 491 | |||
| 492 | cJSON *networks = cJSON_CreateArray(); | ||
| 493 | for (int i = 0; i < g_config.network_count; i++) { | ||
| 494 | cJSON *net = cJSON_CreateObject(); | ||
| 495 | cJSON_AddStringToObject(net, "ssid", g_config.networks[i].ssid); | ||
| 496 | cJSON_AddStringToObject(net, "password", g_config.networks[i].password); | ||
| 497 | cJSON_AddItemToArray(networks, net); | ||
| 498 | } | ||
| 499 | cJSON_AddItemToObject(root, "wifi_networks", networks); | ||
| 500 | |||
| 501 | if (g_config.ap_password[0]) | ||
| 502 | cJSON_AddStringToObject(root, "ap_password", g_config.ap_password); | ||
| 503 | cJSON_AddStringToObject(root, "mint_url", g_config.mint_url); | ||
| 504 | cJSON_AddNumberToObject(root, "price_per_step", g_config.price_per_step); | ||
| 505 | cJSON_AddNumberToObject(root, "step_size_ms", g_config.step_size_ms); | ||
| 506 | |||
| 507 | if (g_config.metric[0]) | ||
| 508 | cJSON_AddStringToObject(root, "metric", g_config.metric); | ||
| 509 | if (g_config.nostr_geohash[0]) | ||
| 510 | cJSON_AddStringToObject(root, "nostr_geohash", g_config.nostr_geohash); | ||
| 511 | |||
| 512 | cJSON *relays = cJSON_CreateArray(); | ||
| 513 | for (int i = 0; i < g_config.nostr_relay_count; i++) { | ||
| 514 | cJSON_AddItemToArray(relays, cJSON_CreateString(g_config.nostr_relays[i])); | ||
| 515 | } | ||
| 516 | cJSON_AddItemToObject(root, "nostr_relays", relays); | ||
| 517 | |||
| 518 | FILE *f = fopen("/spiffs/config.json", "w"); | ||
| 519 | if (f) { | ||
| 520 | char *json = cJSON_PrintUnformatted(root); | ||
| 521 | fputs(json, f); | ||
| 522 | free(json); | ||
| 523 | fclose(f); | ||
| 524 | } | ||
| 525 | cJSON_Delete(root); | ||
| 526 | |||
| 527 | ESP_LOGI(TAG, "WiFi network added: %s (total: %d)", ssid, g_config.network_count); | ||
| 528 | return ESP_OK; | ||
| 529 | } | ||
diff --git a/main/tollgate_main.c b/main/tollgate_main.c index 561fc3f..6c85b28 100644 --- a/main/tollgate_main.c +++ b/main/tollgate_main.c | |||
| @@ -260,7 +260,7 @@ static void start_services(void) | |||
| 260 | display_set_state(DISPLAY_READY); | 260 | display_set_state(DISPLAY_READY); |
| 261 | char portal_url[128]; | 261 | char portal_url[128]; |
| 262 | snprintf(portal_url, sizeof(portal_url), "http://%s/", cfg->ap_ip_str); | 262 | snprintf(portal_url, sizeof(portal_url), "http://%s/", cfg->ap_ip_str); |
| 263 | display_update(cfg->ap_ssid, 0, 0, portal_url); | 263 | display_update(cfg->ap_ssid, 0, 0, portal_url, cfg->mint_url, cfg->price_per_step, "connected"); |
| 264 | } | 264 | } |
| 265 | } | 265 | } |
| 266 | 266 | ||