diff options
| author | Your Name <you@example.com> | 2026-05-19 13:14:48 +0530 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-05-19 13:14:48 +0530 |
| commit | fe6aa9663d4cdabdc6e71db6068f8cd9e3739ffe (patch) | |
| tree | 8cadb07243c07a6b3fa9453b239c9ac5cb02b454 /main/market.h | |
| parent | 77031f06a9a87320d011f501590985161d1eb305 (diff) | |
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.
Diffstat (limited to 'main/market.h')
| -rw-r--r-- | main/market.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/main/market.h b/main/market.h new file mode 100644 index 0000000..6dbf43c --- /dev/null +++ b/main/market.h | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | #ifndef MARKET_H | ||
| 2 | #define MARKET_H | ||
| 3 | |||
| 4 | #include "beacon_price.h" | ||
| 5 | #include "esp_wifi.h" | ||
| 6 | #include "esp_err.h" | ||
| 7 | #include <stdint.h> | ||
| 8 | #include <stdbool.h> | ||
| 9 | |||
| 10 | #define MARKET_MAX_ENTRIES 10 | ||
| 11 | |||
| 12 | typedef struct { | ||
| 13 | uint8_t bssid[6]; | ||
| 14 | char ssid[33]; | ||
| 15 | int8_t rssi; | ||
| 16 | uint16_t price_per_step; | ||
| 17 | uint32_t step_size; | ||
| 18 | uint8_t metric; | ||
| 19 | uint8_t mint_hash[4]; | ||
| 20 | uint8_t npub_hash[4]; | ||
| 21 | char geohash[TOLLGATE_IE_GEOHASH_MAX + 1]; | ||
| 22 | int64_t discovered_ms; | ||
| 23 | bool valid; | ||
| 24 | } market_entry_t; | ||
| 25 | |||
| 26 | typedef struct { | ||
| 27 | market_entry_t entries[MARKET_MAX_ENTRIES]; | ||
| 28 | int count; | ||
| 29 | int64_t last_scan_ms; | ||
| 30 | bool scanning; | ||
| 31 | int consecutive_failures; | ||
| 32 | } market_t; | ||
| 33 | |||
| 34 | esp_err_t market_init(void); | ||
| 35 | void market_tick(void); | ||
| 36 | const market_t *market_get(void); | ||
| 37 | int market_find_cheapest(void); | ||
| 38 | void market_parse_vendor_ie(const uint8_t sa[6], const vendor_ie_data_t *ie, int rssi); | ||
| 39 | |||
| 40 | #endif | ||