feat(client): add scan constants, NVS addr key, and state globals

This commit is contained in:
eddy 2026-08-04 00:29:07 +02:00
commit f07d305621

View file

@ -29,9 +29,11 @@ CRGB leds[NUM_LEDS];
#define NVS_PSK_NAME "psk" #define NVS_PSK_NAME "psk"
#define NVS_UUID_NAME "uuid" #define NVS_UUID_NAME "uuid"
#define NVS_SERVER_NAME "server" #define NVS_SERVER_NAME "server"
#define NVS_ADDR_NAME "addr"
#define DEBOUNCE_MS 50 #define DEBOUNCE_MS 50
#define SCAN_INTERVAL 6000 #define SCAN_DURATION_MS 5000
#define SCAN_TIMEOUT 5000 #define SCAN_INTERVAL_MS 8000
#define RECONNECT_DELAY_MS 1000
uint8_t psk[PSK_LEN]; uint8_t psk[PSK_LEN];
uint8_t deviceUuid[ESP_UUID_LEN]; uint8_t deviceUuid[ESP_UUID_LEN];
@ -40,6 +42,8 @@ bool pskProvisioned = false;
bool uuidProvisioned = false; bool uuidProvisioned = false;
bool serverProvisioned = false; bool serverProvisioned = false;
bool allProvisioned = false; bool allProvisioned = false;
bool serverAddrStored = false;
NimBLEAddress storedServerAddr;
Preferences preferences; Preferences preferences;
static bool connected = false; static bool connected = false;
@ -62,6 +66,9 @@ bool otaEnded = false;
static bool bleReady = false; static bool bleReady = false;
static bool serverFound = false; static bool serverFound = false;
static NimBLEAddress serverAddress; static NimBLEAddress serverAddress;
static bool scanning = false;
static uint32_t scanStarted = 0;
static uint32_t disconnectTime = 0;
static bool ecdhNotifyReceived = false; static bool ecdhNotifyReceived = false;
static uint8_t ecdhNotifyBuf[ECDH_PKT_SIZE]; static uint8_t ecdhNotifyBuf[ECDH_PKT_SIZE];
@ -548,7 +555,7 @@ void loop() {
} }
if (!connected && bleReady) { if (!connected && bleReady) {
if (millis() - lastConnectAttempt > SCAN_INTERVAL) { if (millis() - lastConnectAttempt > SCAN_INTERVAL_MS) {
ESP_LOGI(TAG, "BLE: connecting to server..."); ESP_LOGI(TAG, "BLE: connecting to server...");
if (pClient == nullptr) { if (pClient == nullptr) {
pClient = NimBLEDevice::createClient(); pClient = NimBLEDevice::createClient();