fix: relay pins G1/G2, OTA CCCD+retry, single version source
- Relay pins: G39→G1, G38→G2 - BUNDLED_FIRMWARE_VERSION → SylDaVersions.SERVER (version.txt) - OTA: explicit CCCD descriptor write for Android 13+ - OTA: start packet retry (previously no retry, blocked by pending CCCD) - OTA: firmware path device-mode-aware (server/client subdirs) - Removed stale root firmware.bin, flashMethodGroup, dialog_overwrite_confirm - PrefsHelper: serverUUID/clientUUID persistence
This commit is contained in:
parent
45f8f38e81
commit
a84727abdc
22 changed files with 270 additions and 160 deletions
|
|
@ -223,12 +223,13 @@ void setup() {
|
|||
|
||||
if (allProvisioned) {
|
||||
NimBLEDevice::init("SylDa_Client");
|
||||
NimBLEDevice::setScanFilterMode(CONFIG_BTDM_SCAN_DUPL_TYPE_DATA);
|
||||
|
||||
NimBLEScan *pScan = NimBLEDevice::getScan();
|
||||
pScan->setScanCallbacks(new MyScanCallbacks());
|
||||
pScan->setInterval(97);
|
||||
pScan->setWindow(37);
|
||||
pScan->setActiveScan(false);
|
||||
pScan->setMaxResults(0);
|
||||
bleReady = true;
|
||||
Serial.println("BLE: initialized, will scan for SylDa_Server");
|
||||
}
|
||||
|
|
@ -244,19 +245,21 @@ void loop() {
|
|||
if (c == '\n') {
|
||||
serialBuf.trim();
|
||||
if (serialBuf == "KEY?") {
|
||||
Serial.print("DEVICE_ID:");
|
||||
for (int i = 0; i < ESP_UUID_LEN; i++) Serial.printf("%02X", deviceUuid[i]);
|
||||
Serial.println();
|
||||
Serial.print("HMAC_KEY:");
|
||||
if (keyProvisioned) {
|
||||
if (keyProvisioned && uuidProvisioned) {
|
||||
Serial.print("DEVICE_ID:");
|
||||
for (int i = 0; i < ESP_UUID_LEN; i++) Serial.printf("%02X", deviceUuid[i]);
|
||||
Serial.println();
|
||||
Serial.print("HMAC_KEY:");
|
||||
for (int i = 0; i < HMAC_KEY_LEN; i++) Serial.printf("%02X", hmacKey[i]);
|
||||
Serial.println();
|
||||
Serial.print("SERVER_UUID:");
|
||||
if (serverProvisioned) {
|
||||
for (int i = 0; i < ESP_UUID_LEN; i++) Serial.printf("%02X", serverUuid[i]);
|
||||
}
|
||||
Serial.println();
|
||||
} else {
|
||||
Serial.println("NO_KEY");
|
||||
}
|
||||
Serial.println();
|
||||
Serial.print("SERVER_UUID:");
|
||||
if (serverProvisioned) {
|
||||
for (int i = 0; i < ESP_UUID_LEN; i++) Serial.printf("%02X", serverUuid[i]);
|
||||
}
|
||||
Serial.println();
|
||||
} else if (serialBuf == "VERSION?") {
|
||||
Serial.print("BUILD_NR:");
|
||||
Serial.println(FIRMWARE_VERSION_CLIENT);
|
||||
|
|
@ -274,11 +277,12 @@ void loop() {
|
|||
Serial.println("HMAC key stored in NVS");
|
||||
if (allProvisioned && !bleReady) {
|
||||
NimBLEDevice::init("SylDa_Client");
|
||||
NimBLEDevice::setScanFilterMode(CONFIG_BTDM_SCAN_DUPL_TYPE_DATA);
|
||||
NimBLEScan *pScan = NimBLEDevice::getScan();
|
||||
pScan->setScanCallbacks(new MyScanCallbacks());
|
||||
pScan->setInterval(97);
|
||||
pScan->setWindow(37);
|
||||
pScan->setActiveScan(false);
|
||||
pScan->setMaxResults(0);
|
||||
bleReady = true;
|
||||
Serial.println("BLE: initialized after provisioning");
|
||||
}
|
||||
|
|
@ -314,11 +318,12 @@ void loop() {
|
|||
Serial.println("Server UUID stored in NVS");
|
||||
if (allProvisioned && !bleReady) {
|
||||
NimBLEDevice::init("SylDa_Client");
|
||||
NimBLEDevice::setScanFilterMode(CONFIG_BTDM_SCAN_DUPL_TYPE_DATA);
|
||||
NimBLEScan *pScan = NimBLEDevice::getScan();
|
||||
pScan->setScanCallbacks(new MyScanCallbacks());
|
||||
pScan->setInterval(97);
|
||||
pScan->setWindow(37);
|
||||
pScan->setActiveScan(false);
|
||||
pScan->setMaxResults(0);
|
||||
bleReady = true;
|
||||
Serial.println("BLE: initialized after provisioning");
|
||||
}
|
||||
|
|
|
|||
39
src/main.cpp
39
src/main.cpp
|
|
@ -9,9 +9,10 @@
|
|||
#include <esp_ota_ops.h>
|
||||
#include <esp_partition.h>
|
||||
#include <nvs_flash.h>
|
||||
#include "version.h"
|
||||
|
||||
#define RELAY1_PIN 39
|
||||
#define RELAY2_PIN 38
|
||||
#define RELAY1_PIN 1
|
||||
#define RELAY2_PIN 2
|
||||
#define TOUCH1_PIN 8
|
||||
#define TOUCH2_PIN 6
|
||||
#define BUTTON_PIN 41
|
||||
|
|
@ -41,12 +42,11 @@ CRGB leds[NUM_LEDS];
|
|||
#define NVS_NAMESPACE "hmac"
|
||||
#define NVS_KEY_NAME "key"
|
||||
#define NVS_UUID_NAME "uuid"
|
||||
#define FIRMWARE_VERSION "6"
|
||||
#define FIRMWARE_VERSION FIRMWARE_VERSION_SERVER
|
||||
|
||||
NimBLECharacteristic *pCharacteristic;
|
||||
bool relay1State = false;
|
||||
bool relay2State = false;
|
||||
bool buttonToggle = false;
|
||||
|
||||
bool connActive[MAX_CLIENTS] = {false, false};
|
||||
bool bleRelay1[MAX_CLIENTS] = {false, false};
|
||||
|
|
@ -94,15 +94,14 @@ class MyServerCallbacks : public NimBLEServerCallbacks {
|
|||
bleRelay2[slot] = false;
|
||||
lastSeq[slot] = 0;
|
||||
connectedCount++;
|
||||
Serial.printf("BLE: device connected (conn=%d, slot=%d, clients=%d/%d)\n",
|
||||
handle, slot, connectedCount, MAX_CLIENTS);
|
||||
Serial.printf("BLE: device connected (conn=%d, slot=%d, clients=%d/%d, mac=%s)\n",
|
||||
handle, slot, connectedCount, MAX_CLIENTS,
|
||||
connInfo.getAddress().toString().c_str());
|
||||
} else {
|
||||
Serial.printf("BLE: device connected but no free slot (conn=%d, clients=%d/%d)\n",
|
||||
handle, connectedCount, MAX_CLIENTS);
|
||||
}
|
||||
if (connectedCount < MAX_CLIENTS) {
|
||||
NimBLEDevice::startAdvertising();
|
||||
}
|
||||
pServer->startAdvertising();
|
||||
}
|
||||
void onDisconnect(NimBLEServer *pServer, NimBLEConnInfo &connInfo, int reason) override {
|
||||
uint16_t handle = connInfo.getConnHandle();
|
||||
|
|
@ -114,14 +113,12 @@ class MyServerCallbacks : public NimBLEServerCallbacks {
|
|||
lastSeq[i] = 0;
|
||||
connHandles[i] = 0xFFFF;
|
||||
connectedCount--;
|
||||
Serial.printf("BLE: device disconnected (conn=%d, slot=%d, clients=%d/%d)\n",
|
||||
handle, i, connectedCount, MAX_CLIENTS);
|
||||
Serial.printf("BLE: device disconnected (conn=%d, slot=%d, clients=%d/%d, mac=%s)\n",
|
||||
handle, i, connectedCount, MAX_CLIENTS,
|
||||
connInfo.getAddress().toString().c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (connectedCount < MAX_CLIENTS) {
|
||||
NimBLEDevice::startAdvertising();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -322,8 +319,9 @@ class MyCharacteristicCallbacks : public NimBLECharacteristicCallbacks {
|
|||
|
||||
std::string value = pChar->getValue();
|
||||
if (value.length() != HMAC_PKT_SIZE) {
|
||||
Serial.printf("BLE: bad packet length %d (expected %d)\n",
|
||||
(int)value.length(), HMAC_PKT_SIZE);
|
||||
Serial.printf("BLE: bad packet length %d (expected %d), slot=%d mac=%s\n",
|
||||
(int)value.length(), HMAC_PKT_SIZE, idx,
|
||||
connInfo.getAddress().toString().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -540,15 +538,8 @@ void loop() {
|
|||
bool t2Active = (millis() - t2Change > DEBOUNCE_MS) && t2Stable;
|
||||
bool btnActive = (millis() - btnChange > DEBOUNCE_MS) && btnStable;
|
||||
|
||||
static bool prevBtnActive = false;
|
||||
if (btnActive && !prevBtnActive) {
|
||||
buttonToggle = !buttonToggle;
|
||||
Serial.printf("Button: toggle -> %s\n", buttonToggle ? "ON" : "OFF");
|
||||
}
|
||||
prevBtnActive = btnActive;
|
||||
|
||||
if (!otaInProgress) {
|
||||
relay1State = t1Active || (buttonToggle && digitalRead(BUTTON_PIN) != LOW) ||
|
||||
relay1State = t1Active || btnActive ||
|
||||
(connActive[0] && bleRelay1[0]) || (connActive[1] && bleRelay1[1]);
|
||||
relay2State = t2Active ||
|
||||
(connActive[0] && bleRelay2[0]) || (connActive[1] && bleRelay2[1]);
|
||||
|
|
|
|||
Loading…
Reference in a new issue