From fe6aa9663d4cdabdc6e71db6068f8cd9e3739ffe Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 19 May 2026 13:14:48 +0530 Subject: feat: WiFi beacon price discovery via Vendor IE (two-board verified) Price discovery allows TollGate ESP32 boards to advertise their per-step price via WiFi Vendor-Specific Information Elements (OUI 0xC0FFEE) in beacon and probe response frames. Nearby boards passively scan and build a market view of competing TollGates without requiring internet access. Features: - beacon_price.c/h: 26-byte packed Vendor IE payload (price, step, metric, mint_hash, geohash, npub_hash), injected via esp_wifi_set_vendor_ie() - market.c/h: Passive WiFi scan receiver, vendor IE callback parsing, BSSID-correlated market entries, effective price ranking - GET /market API endpoint: JSON market snapshot with discovered entries - AP-only services: beacon + market + API start on WIFI_EVENT_AP_START, independent of STA connectivity - STA reconnect fix: 2s delay between retries creates scan windows; s_sta_connecting guard prevents double-connect - write-config-ap-only-a/b Makefile targets for STA-less testing - market_tick() in main loop, client price comparison logging Hardware verified: both boards discover each other via Vendor IE beacons. Board A sees TollGate-C0E9CA (RSSI=-30), Board B sees TollGate-B96D80 (RSSI=-25). test-market.mjs: 9/9, test-price-discovery.mjs: 7/7 per board. Unit tests: 45 new assertions across test_beacon_price (28) and test_market (17). All 15 test suites pass. ESP-IDF build clean for ESP32-S3. --- main/tollgate_client.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'main/tollgate_client.c') diff --git a/main/tollgate_client.c b/main/tollgate_client.c index ac8dcfe..a81d16f 100644 --- a/main/tollgate_client.c +++ b/main/tollgate_client.c @@ -1,6 +1,7 @@ #include "tollgate_client.h" #include "config.h" #include "nucula_wallet.h" +#include "market.h" #include "esp_log.h" #include "esp_http_client.h" #include "esp_crt_bundle.h" @@ -343,6 +344,19 @@ esp_err_t tollgate_client_on_sta_connected(const char *gw_ip_str) s_state = TG_CLIENT_PAID; ESP_LOGI(TAG, "upstream TollGate paid: %lldms allotment", (long long)allotment); + + const market_t *mkt = market_get(); + int cheapest = market_find_cheapest(); + if (cheapest >= 0 && mkt->entries[cheapest].valid && mkt->entries[cheapest].ssid[0] != '\0') { + uint32_t upstream_step = s_discovery.step_size_ms > 0 ? s_discovery.step_size_ms : 1; + uint32_t upstream_eff = (uint32_t)s_discovery.price_per_step * 60000 / upstream_step; + uint32_t cheap_step = mkt->entries[cheapest].step_size > 0 ? mkt->entries[cheapest].step_size : 1; + uint32_t cheap_eff = (uint32_t)mkt->entries[cheapest].price_per_step * 60000 / cheap_step; + if (cheap_eff < upstream_eff) { + ESP_LOGW(TAG, "CHEAPER TOLLGATE AVAILABLE: %s at %lu sats/min vs upstream %lu sats/min", + mkt->entries[cheapest].ssid, (unsigned long)cheap_eff, (unsigned long)upstream_eff); + } + } return ESP_OK; } -- cgit v1.2.3