Fix BLE scan + touch logic + UUID + version read
- Client: change passive BLE scan to active scan (setActiveScan(true)) Server puts name/UUID in scan response; passive scan never received them, so isAdvertisingService() and getName() failed. - Server: add INPUT_PULLUP on touch pins to prevent floating triggers when sensors disconnected - Server: update BLE UUID characteristic in SET_ID handler (pUuidChar->setValue) so reconnecting clients see correct UUID - Server: touch logic changed from t1Active/t2Active to !t1Active/!t2Active (door closed = relay ON) - Android: flushReadBuffer before VERSION? to discard stale boot log output; use Regex for BUILD_NR parsing - copy_firmware.sh: copy to firmware/server/ and firmware/client/ subdirectories to match EspFlasher.assetPath() - version.txt: server=20 client=5
This commit is contained in:
parent
6a07505d02
commit
cd2d949f87
7 changed files with 64 additions and 31 deletions
13
src/main.cpp
13
src/main.cpp
|
|
@ -48,6 +48,7 @@ CRGB leds[NUM_LEDS];
|
|||
#define FIRMWARE_VERSION FIRMWARE_VERSION_SERVER
|
||||
|
||||
NimBLECharacteristic *pCharacteristic;
|
||||
NimBLECharacteristic *pUuidChar;
|
||||
bool relay1State = false;
|
||||
bool relay2State = false;
|
||||
|
||||
|
|
@ -401,8 +402,8 @@ void setup() {
|
|||
ESP_LOGD(TAG, "Generated new UUID");
|
||||
}
|
||||
|
||||
pinMode(TOUCH1_PIN, INPUT);
|
||||
pinMode(TOUCH2_PIN, INPUT);
|
||||
pinMode(TOUCH1_PIN, INPUT_PULLUP);
|
||||
pinMode(TOUCH2_PIN, INPUT_PULLUP);
|
||||
pinMode(BUTTON_PIN, INPUT);
|
||||
pinMode(RELAY1_PIN, OUTPUT);
|
||||
pinMode(RELAY2_PIN, OUTPUT);
|
||||
|
|
@ -424,7 +425,7 @@ void setup() {
|
|||
);
|
||||
pCharacteristic->setCallbacks(new MyCharacteristicCallbacks());
|
||||
|
||||
NimBLECharacteristic *pUuidChar = pService->createCharacteristic(
|
||||
pUuidChar = pService->createCharacteristic(
|
||||
UUID_CHAR_UUID,
|
||||
NIMBLE_PROPERTY::READ
|
||||
);
|
||||
|
|
@ -488,6 +489,7 @@ void loop() {
|
|||
} else if (serialBuf == "ID?") {
|
||||
Serial.println("SylDa_Server");
|
||||
} else if (serialBuf == "VERSION?") {
|
||||
Serial.flush();
|
||||
Serial.print("BUILD_NR:");
|
||||
Serial.println(FIRMWARE_VERSION);
|
||||
} else if (serialBuf.startsWith("SET_KEY:")) {
|
||||
|
|
@ -515,6 +517,7 @@ void loop() {
|
|||
preferences.putBytes(NVS_UUID_NAME, deviceUuid, ESP_UUID_LEN);
|
||||
preferences.end();
|
||||
uuidProvisioned = true;
|
||||
pUuidChar->setValue(deviceUuid, ESP_UUID_LEN);
|
||||
Serial.println("OK");
|
||||
Serial.println("UUID stored in NVS");
|
||||
} else {
|
||||
|
|
@ -585,9 +588,9 @@ void loop() {
|
|||
bool btnActive = (millis() - btnChange > DEBOUNCE_MS) && btnStable;
|
||||
|
||||
if (!otaInProgress) {
|
||||
relay1State = t1Active || btnActive ||
|
||||
relay1State = !t1Active || btnActive ||
|
||||
(connActive[0] && bleRelay1[0]) || (connActive[1] && bleRelay1[1]);
|
||||
relay2State = t2Active ||
|
||||
relay2State = !t2Active ||
|
||||
(connActive[0] && bleRelay2[0]) || (connActive[1] && bleRelay2[1]);
|
||||
} else {
|
||||
relay1State = false;
|
||||
|
|
|
|||
Loading…
Reference in a new issue