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/beacon_price.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 main/beacon_price.h (limited to 'main/beacon_price.h') diff --git a/main/beacon_price.h b/main/beacon_price.h new file mode 100644 index 0000000..cb2eb5b --- /dev/null +++ b/main/beacon_price.h @@ -0,0 +1,44 @@ +#ifndef BEACON_PRICE_H +#define BEACON_PRICE_H + +#include "esp_err.h" +#include +#include + +#define TOLLGATE_OUI_0 0xC0 +#define TOLLGATE_OUI_1 0xFF +#define TOLLGATE_OUI_2 0xEE +#define TOLLGATE_IE_TYPE 0x01 +#define TOLLGATE_IE_VERSION 1 + +#define TOLLGATE_IE_GEOHASH_MAX 9 + +typedef struct __attribute__((packed)) { + uint8_t version; + uint8_t metric; + uint16_t price_per_step; + uint32_t step_size; + uint8_t mint_hash[4]; + uint8_t geohash_len; + char geohash[TOLLGATE_IE_GEOHASH_MAX]; + uint8_t npub_hash[4]; +} tollgate_price_payload_t; + +#define TOLLGATE_IE_PAYLOAD_SIZE sizeof(tollgate_price_payload_t) +#define TOLLGATE_IE_TOTAL_SIZE (6 + TOLLGATE_IE_PAYLOAD_SIZE) + +typedef struct __attribute__((packed)) { + uint8_t element_id; + uint8_t length; + uint8_t vendor_oui[3]; + uint8_t vendor_oui_type; + tollgate_price_payload_t payload; +} tollgate_price_ie_t; + +esp_err_t beacon_price_start(void); +esp_err_t beacon_price_stop(void); +void beacon_price_build_ie(tollgate_price_ie_t *ie); +void beacon_price_hash_mint(const char *mint_url, uint8_t hash_out[4]); +void beacon_price_hash_npub(const char *npub_hex, uint8_t hash_out[4]); + +#endif -- cgit v1.2.3