diff --git a/platformio.ini b/platformio.ini index f02579d..f46d332 100644 --- a/platformio.ini +++ b/platformio.ini @@ -5,7 +5,7 @@ framework = arduino board_build.arduino.memory_type = qio_qspi build_flags = -DESP32S3 - -DCORE_DEBUG_LEVEL=3 + -DCORE_DEBUG_LEVEL=5 -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MODE=1 lib_deps = @@ -24,7 +24,7 @@ framework = arduino board_build.arduino.memory_type = qio_qspi build_flags = -DESP32S3 - -DCORE_DEBUG_LEVEL=3 + -DCORE_DEBUG_LEVEL=5 -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MODE=1 -DDEVICE_ID=1 diff --git a/src/client.cpp b/src/client.cpp index 0dc079c..059d4b8 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -6,11 +6,8 @@ #include #include -#include #include "version.h" -static const char *TAG = "client"; - #define TOUCH1_PIN 8 #define TOUCH2_PIN 6 #define BUTTON_PIN 41 @@ -73,14 +70,14 @@ class MyScanCallbacks : public NimBLEScanCallbacks { class MyClientCallbacks : public NimBLEClientCallbacks { void onConnect(NimBLEClient *client) override { connected = true; - ESP_LOGI(TAG, "BLE: connected to server"); + Serial.println("BLE: connected to server"); } void onDisconnect(NimBLEClient *client, int reason) override { connected = false; relay1SendState = false; relay2SendState = false; pCmdChar = nullptr; - ESP_LOGW(TAG, "BLE: disconnected (reason=%d)", reason); + Serial.printf("BLE: disconnected (reason=%d)\n", reason); } }; @@ -132,7 +129,7 @@ static bool connectToServer() { pClient->setClientCallbacks(&clientCallbacks); if (!pClient->connect(serverAddress)) { - ESP_LOGE(TAG, "BLE: connect failed"); + Serial.println("BLE: connect failed"); NimBLEDevice::deleteClient(pClient); pClient = nullptr; return false; @@ -140,14 +137,14 @@ static bool connectToServer() { NimBLERemoteService *pSvc = pClient->getService(SERVICE_UUID); if (pSvc == nullptr) { - ESP_LOGW(TAG, "BLE: service not found"); + Serial.println("BLE: service not found"); disconnectClient(); return false; } NimBLERemoteCharacteristic *pUuidChar = pSvc->getCharacteristic(UUID_CHAR_UUID); if (pUuidChar == nullptr) { - ESP_LOGW(TAG, "BLE: UUID characteristic not found"); + Serial.println("BLE: UUID characteristic not found"); disconnectClient(); return false; } @@ -155,14 +152,14 @@ static bool connectToServer() { std::string uuidVal = pUuidChar->readValue(); if (uuidVal.length() != ESP_UUID_LEN || memcmp(uuidVal.data(), serverUuid, ESP_UUID_LEN) != 0) { - ESP_LOGW(TAG, "BLE: server UUID mismatch — disconnecting"); + Serial.println("BLE: server UUID mismatch — disconnecting"); disconnectClient(); return false; } pCmdChar = pSvc->getCharacteristic(CHARACTERISTIC_UUID); if (pCmdChar == nullptr) { - ESP_LOGW(TAG, "BLE: command characteristic not found"); + Serial.println("BLE: command characteristic not found"); disconnectClient(); return false; } @@ -170,14 +167,14 @@ static bool connectToServer() { seq = 0; relay1SendState = false; relay2SendState = false; - ESP_LOGI(TAG, "BLE: server UUID verified, ready"); + Serial.println("BLE: server UUID verified, ready"); return true; } void setup() { Serial.begin(115200); delay(2000); - ESP_LOGI(TAG, "=== SylDa Client v%s ===", FIRMWARE_VERSION_CLIENT); + Serial.println("=== SylDa Client ==="); FastLED.addLeds(leds, NUM_LEDS); leds[0] = CRGB::Red; @@ -191,15 +188,17 @@ void setup() { if (len == HMAC_KEY_LEN) { keyProvisioned = true; - ESP_LOGI(TAG, "HMAC key loaded from NVS"); + Serial.println("HMAC key loaded from NVS"); } else { keyProvisioned = false; - ESP_LOGW(TAG, "No HMAC key — use USB SET_KEY to provision"); + Serial.println("No HMAC key — use USB SET_KEY to provision"); } if (uuidLen == ESP_UUID_LEN) { uuidProvisioned = true; - ESP_LOGD(TAG, "UUID loaded from NVS"); + Serial.print("UUID loaded from NVS: "); + for (int i = 0; i < ESP_UUID_LEN; i++) Serial.printf("%02X", deviceUuid[i]); + Serial.println(); } else { uuidProvisioned = false; for (int i = 0; i < ESP_UUID_LEN; i++) deviceUuid[i] = (uint8_t)(esp_random() & 0xFF); @@ -207,15 +206,19 @@ void setup() { preferences.putBytes(NVS_UUID_NAME, deviceUuid, ESP_UUID_LEN); preferences.end(); uuidProvisioned = true; - ESP_LOGD(TAG, "Generated new UUID"); + Serial.print("Generated new UUID: "); + for (int i = 0; i < ESP_UUID_LEN; i++) Serial.printf("%02X", deviceUuid[i]); + Serial.println(); } if (serverLen == ESP_UUID_LEN) { serverProvisioned = true; - ESP_LOGD(TAG, "Server UUID loaded from NVS"); + Serial.print("Server UUID loaded from NVS: "); + for (int i = 0; i < ESP_UUID_LEN; i++) Serial.printf("%02X", serverUuid[i]); + Serial.println(); } else { serverProvisioned = false; - ESP_LOGW(TAG, "No server UUID — use USB SET_SERVER to provision"); + Serial.println("No server UUID — use USB SET_SERVER to provision"); } allProvisioned = keyProvisioned && uuidProvisioned && serverProvisioned; @@ -234,10 +237,10 @@ void setup() { pScan->setActiveScan(false); pScan->setMaxResults(0); bleReady = true; - ESP_LOGI(TAG, "BLE: initialized, will scan for SylDa_Server"); + Serial.println("BLE: initialized, will scan for SylDa_Server"); } - ESP_LOGI(TAG, "Setup done."); + Serial.println("Setup done."); } void loop() { @@ -287,11 +290,10 @@ void loop() { pScan->setActiveScan(false); pScan->setMaxResults(0); bleReady = true; - ESP_LOGI(TAG, "BLE: initialized after key provisioning"); + Serial.println("BLE: initialized after provisioning"); } } else { - ESP_LOGE(TAG, "Invalid key format"); - Serial.println("ERROR"); + Serial.println("ERROR: invalid key format"); } } else if (serialBuf.startsWith("SET_ID:")) { String hex = serialBuf.substring(7); @@ -306,8 +308,7 @@ void loop() { Serial.println("OK"); Serial.println("UUID stored in NVS"); } else { - ESP_LOGE(TAG, "Invalid UUID format"); - Serial.println("ERROR"); + Serial.println("ERROR: invalid UUID format"); } } else if (serialBuf.startsWith("SET_SERVER:")) { String hex = serialBuf.substring(11); @@ -330,11 +331,10 @@ void loop() { pScan->setActiveScan(false); pScan->setMaxResults(0); bleReady = true; - ESP_LOGI(TAG, "BLE: initialized after server provisioning"); + Serial.println("BLE: initialized after provisioning"); } } else { - ESP_LOGE(TAG, "Invalid server UUID format"); - Serial.println("ERROR"); + Serial.println("ERROR: invalid server UUID format"); } } serialBuf = ""; @@ -363,6 +363,9 @@ void loop() { bool btnActive = (millis() - btnChange > DEBOUNCE_MS) && btnStable; static bool prevBtnActive = false; + if (btnActive && !prevBtnActive) { + Serial.printf("Button: pressed\n"); + } prevBtnActive = btnActive; bool relay1State = !t1Active || btnActive; @@ -412,7 +415,7 @@ void loop() { buildHmacPacket(relay1State ? 0x01 : 0x00, pkt); pCmdChar->writeValue(pkt, HMAC_PKT_SIZE, false); relay1SendState = relay1State; - ESP_LOGD(TAG, "TX: relay1 %s (seq=%lu)", relay1State ? "ON" : "OFF", seq); + Serial.printf("TX: relay1 %s (seq=%lu)\n", relay1State ? "ON" : "OFF", seq); lastCmd = millis(); } if (relay2State != relay2SendState) { @@ -420,7 +423,7 @@ void loop() { buildHmacPacket(relay2State ? 0x02 : 0x03, pkt); pCmdChar->writeValue(pkt, HMAC_PKT_SIZE, false); relay2SendState = relay2State; - ESP_LOGD(TAG, "TX: relay2 %s (seq=%lu)", relay2State ? "ON" : "OFF", seq); + Serial.printf("TX: relay2 %s (seq=%lu)\n", relay2State ? "ON" : "OFF", seq); lastCmd = millis(); } } @@ -441,20 +444,21 @@ void loop() { if (!pScan->isScanning() && scanRunnable) { scanRunnable = false; if (serverFound) { - ESP_LOGI(TAG, "BLE: found SylDa_Server, connecting..."); + Serial.printf("BLE: found SylDa_Server (%s), connecting...\n", + serverAddress.toString().c_str()); connectToServer(); } } } if (connected && pClient != nullptr && !pClient->isConnected()) { - ESP_LOGW(TAG, "BLE: lost connection"); + Serial.println("BLE: lost connection"); disconnectClient(); } static uint32_t heartbeat = 0; if (millis() - heartbeat > 60000) { - ESP_LOGD(TAG, "[heartbeat] t1=%s t2=%s btn=%s r1=%s r2=%s connected=%s", + Serial.printf("[heartbeat] t1=%s t2=%s btn=%s r1=%s r2=%s connected=%s\n", !t1Active ? "YES" : "no", !t2Active ? "YES" : "no", btnActive ? "YES" : "no", diff --git a/src/main.cpp b/src/main.cpp index e12cbd5..06255a5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,11 +9,8 @@ #include #include #include -#include #include "version.h" -static const char *TAG = "server"; - #define RELAY1_PIN 1 #define RELAY2_PIN 2 #define TOUCH1_PIN 8 @@ -107,12 +104,12 @@ class MyServerCallbacks : public NimBLEServerCallbacks { bleRelay2[slot] = false; lastSeq[slot] = 0; connectedCount++; - ESP_LOGI(TAG, "BLE: connected (slot=%d, clients=%d/%d, mac=%s)", - slot, connectedCount, MAX_CLIENTS, - connInfo.getAddress().toString().c_str()); + 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 { - ESP_LOGW(TAG, "BLE: connected but no free slot (clients=%d/%d)", - connectedCount, MAX_CLIENTS); + Serial.printf("BLE: device connected but no free slot (conn=%d, clients=%d/%d)\n", + handle, connectedCount, MAX_CLIENTS); } pServer->startAdvertising(); } @@ -126,9 +123,9 @@ class MyServerCallbacks : public NimBLEServerCallbacks { lastSeq[i] = 0; connHandles[i] = 0xFFFF; connectedCount--; - ESP_LOGI(TAG, "BLE: disconnected (slot=%d, clients=%d/%d, mac=%s)", - i, connectedCount, MAX_CLIENTS, - connInfo.getAddress().toString().c_str()); + 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; } } @@ -137,7 +134,7 @@ class MyServerCallbacks : public NimBLEServerCallbacks { static bool verifyHmac(const uint8_t *packet, int idx) { if (idx < 0 || idx >= MAX_CLIENTS || !connActive[idx]) { - ESP_LOGW(TAG, "HMAC verify for invalid idx=%d", idx); + Serial.printf("BLE: HMAC verify called for invalid idx=%d\n", idx); return false; } @@ -148,7 +145,7 @@ static bool verifyHmac(const uint8_t *packet, int idx) { (uint32_t)packet[4]; if (seq <= lastSeq[idx]) { - ESP_LOGW(TAG, "Replay rejected (seq=%lu, last=%lu, slot=%d)", seq, lastSeq[idx], idx); + Serial.printf("BLE: replay rejected (seq=%lu, last=%lu, slot=%d)\n", seq, lastSeq[idx], idx); return false; } @@ -164,7 +161,7 @@ static bool verifyHmac(const uint8_t *packet, int idx) { mbedtls_md_hmac(mdInfo, hmacKey, HMAC_KEY_LEN, hmacData, 5, computed); if (memcmp(computed, packet + 5, 32) != 0) { - ESP_LOGE(TAG, "HMAC mismatch"); + Serial.println("BLE: HMAC mismatch"); return false; } @@ -212,12 +209,12 @@ static void sendOtaNotify(NimBLECharacteristic *otaChar, uint8_t status, uint32_ otaChar->setValue(buf, 5); bool ok = otaChar->notify(); if (!ok) { - ESP_LOGW(TAG, "OTA notify() failed (status=0x%02X seq=%lu)", status, seq); + Serial.printf("OTA: notify() returned false for status=0x%02X seq=%lu\n", status, seq); } } static void abortOta(NimBLECharacteristic *otaChar, const char *reason) { - ESP_LOGE(TAG, "OTA: abort — %s", reason); + Serial.printf("OTA: abort — %s\n", reason); if (otaHandle != 0) { esp_ota_end(otaHandle); } @@ -241,13 +238,13 @@ class OtaCharacteristicCallbacks : public NimBLECharacteristicCallbacks { ((uint32_t)data[3] << 8) | (uint32_t)data[4]; otaPartition = esp_ota_get_next_update_partition(nullptr); if (otaPartition == nullptr) { - ESP_LOGE(TAG, "OTA: no update partition found"); + Serial.println("OTA: no update partition found"); sendOtaNotify(pChar, OTA_STATUS_ERROR, 0); return; } esp_err_t err = esp_ota_begin(otaPartition, otaExpectedSize, &otaHandle); if (err != ESP_OK) { - ESP_LOGE(TAG, "OTA: begin failed (%d)", err); + Serial.printf("OTA: begin failed (%d)\n", err); sendOtaNotify(pChar, OTA_STATUS_ERROR, 0); return; } @@ -264,7 +261,7 @@ class OtaCharacteristicCallbacks : public NimBLECharacteristicCallbacks { bleRelay1[i] = false; bleRelay2[i] = false; } - ESP_LOGI(TAG, "OTA: started, expecting %lu bytes", otaExpectedSize); + Serial.printf("OTA: started, expecting %lu bytes\n", otaExpectedSize); return; } @@ -275,35 +272,37 @@ class OtaCharacteristicCallbacks : public NimBLECharacteristicCallbacks { mbedtls_sha256_free(&otaShaCtx); otaShaStarted = false; - ESP_LOGD(TAG, "OTA: SHA256 verify (written=%lu expected=%lu)", otaWritten, otaExpectedSize); + Serial.printf("OTA: SHA256 verify — written=%lu expected=%lu\n", otaWritten, otaExpectedSize); if (memcmp(computedSha, otaExpectedSha, 32) != 0) { - ESP_LOGE(TAG, "OTA: SHA256 mismatch — aborting"); + Serial.println("OTA: SHA256 mismatch — aborting"); esp_ota_abort(otaHandle); otaReset(); sendOtaNotify(pChar, OTA_STATUS_ERROR, 0); return; } - ESP_LOGI(TAG, "OTA: SHA256 OK, waiting for 0xFF confirm"); + Serial.println("OTA: SHA256 OK, setting otaReady=true, sending COMPLETE notify"); otaReady = true; sendOtaNotify(pChar, OTA_STATUS_COMPLETE, 0); + Serial.printf("OTA: COMPLETE notify sent, otaReady=%d, otaConfirmed=%d, otaInProgress=%d\n", + otaReady, otaConfirmed, otaInProgress); return; } if (!otaInProgress) { - ESP_LOGD(TAG, "OTA: write ignored (not in progress, len=%d data0=0x%02X)", len, data[0]); + Serial.printf("OTA: write ignored — otaInProgress=false (len=%d, data0=0x%02X)\n", len, data[0]); return; } if (len == 1 && data[0] == 0xFF) { - ESP_LOGD(TAG, "OTA: 0xFF received (ready=%d ended=%d confirmed=%d inProgress=%d)", - otaReady, otaEnded, otaConfirmed, otaInProgress); + Serial.printf("OTA: 0xFF received — otaReady=%d, otaEnded=%d, otaConfirmed=%d, otaInProgress=%d\n", + otaReady, otaEnded, otaConfirmed, otaInProgress); if (!otaEnded) { - ESP_LOGD(TAG, "OTA: 0xFF arrived early, deferring"); + Serial.println("OTA: 0xFF arrived early (esp_ota_end not yet called), deferring"); otaEarlyConfirm = true; return; } - ESP_LOGI(TAG, "OTA: 0xFF confirm accepted"); + Serial.println("OTA: 0xFF confirm accepted, setting otaConfirmed=true"); otaConfirmed = true; return; } @@ -313,9 +312,12 @@ class OtaCharacteristicCallbacks : public NimBLECharacteristicCallbacks { ((uint32_t)data[2] << 8) | (uint32_t)data[3]; size_t dataLen = len - 4; mbedtls_sha256_update_ret(&otaShaCtx, data + 4, dataLen); + unsigned long t0 = micros(); esp_err_t err = esp_ota_write(otaHandle, data + 4, dataLen); + unsigned long elapsed = micros() - t0; + Serial.printf("OTA: chunk %lu write %d bytes in %lu us\n", seq, dataLen, elapsed); if (err != ESP_OK) { - ESP_LOGE(TAG, "OTA: write error at seq %lu (%d)", seq, err); + Serial.printf("OTA: write err at seq %lu (%d)\n", seq, err); sendOtaNotify(pChar, OTA_STATUS_NAK, seq); abortOta(pChar, "write error"); return; @@ -332,14 +334,15 @@ class MyCharacteristicCallbacks : public NimBLECharacteristicCallbacks { int idx = findClientIdx(connInfo.getConnHandle()); if (idx < 0) { - ESP_LOGW(TAG, "BLE: write from unknown conn handle %d", connInfo.getConnHandle()); + Serial.printf("BLE: write from unknown conn handle %d\n", connInfo.getConnHandle()); return; } std::string value = pChar->getValue(); if (value.length() != HMAC_PKT_SIZE) { - ESP_LOGW(TAG, "BLE: bad packet length %d (expected %d), slot=%d", - (int)value.length(), HMAC_PKT_SIZE, idx); + 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; } @@ -354,16 +357,16 @@ class MyCharacteristicCallbacks : public NimBLECharacteristicCallbacks { if (cmd == 0x01) { bleRelay1[idx] = true; - ESP_LOGI(TAG, "BLE: relay1 ON (seq=%lu, slot=%d)", seq, idx); + Serial.printf("BLE: relay1 ON (seq=%lu, slot=%d)\n", seq, idx); } else if (cmd == 0x00) { bleRelay1[idx] = false; - ESP_LOGI(TAG, "BLE: relay1 OFF (seq=%lu, slot=%d)", seq, idx); + Serial.printf("BLE: relay1 OFF (seq=%lu, slot=%d)\n", seq, idx); } else if (cmd == 0x02) { bleRelay2[idx] = true; - ESP_LOGI(TAG, "BLE: relay2 ON (seq=%lu, slot=%d)", seq, idx); + Serial.printf("BLE: relay2 ON (seq=%lu, slot=%d)\n", seq, idx); } else if (cmd == 0x03) { bleRelay2[idx] = false; - ESP_LOGI(TAG, "BLE: relay2 OFF (seq=%lu, slot=%d)", seq, idx); + Serial.printf("BLE: relay2 OFF (seq=%lu, slot=%d)\n", seq, idx); } } }; @@ -371,7 +374,7 @@ class MyCharacteristicCallbacks : public NimBLECharacteristicCallbacks { void setup() { Serial.begin(115200); delay(2000); - ESP_LOGI(TAG, "=== AtomS3 Lite BLE Relay v%s ===", FIRMWARE_VERSION); + Serial.println("=== AtomS3 Lite BLE Relay ==="); FastLED.addLeds(leds, NUM_LEDS); @@ -382,15 +385,17 @@ void setup() { if (len == HMAC_KEY_LEN) { keyProvisioned = true; - ESP_LOGI(TAG, "HMAC key loaded from NVS"); + Serial.println("HMAC key loaded from NVS"); } else { keyProvisioned = false; - ESP_LOGW(TAG, "No HMAC key — connect USB and run SET_KEY"); + Serial.println("No HMAC key provisioned — connect USB and run SET_KEY"); } if (uuidLen == ESP_UUID_LEN) { uuidProvisioned = true; - ESP_LOGD(TAG, "UUID loaded from NVS"); + Serial.print("UUID loaded from NVS: "); + for (int i = 0; i < ESP_UUID_LEN; i++) Serial.printf("%02X", deviceUuid[i]); + Serial.println(); } else { uuidProvisioned = false; for (int i = 0; i < ESP_UUID_LEN; i++) deviceUuid[i] = (uint8_t)(esp_random() & 0xFF); @@ -398,7 +403,9 @@ void setup() { preferences.putBytes(NVS_UUID_NAME, deviceUuid, ESP_UUID_LEN); preferences.end(); uuidProvisioned = true; - ESP_LOGD(TAG, "Generated new UUID"); + Serial.print("Generated new UUID: "); + for (int i = 0; i < ESP_UUID_LEN; i++) Serial.printf("%02X", deviceUuid[i]); + Serial.println(); } pinMode(TOUCH1_PIN, INPUT); @@ -409,6 +416,7 @@ void setup() { leds[0] = CRGB::Red; FastLED.show(); + Serial.println("LED red (no connection), starting BLE..."); NimBLEDevice::init("SylDa_Server"); NimBLEDevice::setMTU(248); @@ -454,15 +462,20 @@ void setup() { pAdvertising->setMinInterval(32); pAdvertising->setMaxInterval(64); bool advOk = pAdvertising->start(); - ESP_LOGI(TAG, "BLE: advertising started"); + Serial.printf("BLE: advertising started as 'SylDa_Server' (start=%d, isAdv=%d)\n", + advOk, pAdvertising->isAdvertising()); if (keyProvisioned) { - ESP_LOGD(TAG, "HMAC key present"); + Serial.print("HMAC Key: "); + for (int i = 0; i < HMAC_KEY_LEN; i++) { + Serial.printf("%02X", hmacKey[i]); + } + Serial.println(); } else { - ESP_LOGW(TAG, "No HMAC key — use USB SET_KEY to provision"); + Serial.println("No HMAC key — use USB SET_KEY to provision"); } - ESP_LOGI(TAG, "Setup done."); + Serial.println("Setup done."); } void loop() { @@ -524,41 +537,43 @@ void loop() { } if (otaReady) { - ESP_LOGD(TAG, "OTA: processing otaReady (written=%lu expected=%lu)", - otaWritten, otaExpectedSize); + Serial.printf("OTA: loop() processing otaReady — otaWritten=%lu, otaExpectedSize=%lu\n", + otaWritten, otaExpectedSize); esp_err_t err = esp_ota_end(otaHandle); if (err != ESP_OK) { - ESP_LOGE(TAG, "OTA: esp_ota_end failed (%d) — aborting", err); + Serial.printf("OTA: esp_ota_end failed (%d) — aborting\n", err); otaReset(); } else { - ESP_LOGI(TAG, "OTA: esp_ota_end OK, waiting for 0xFF confirm"); + Serial.println("OTA: esp_ota_end OK, setting otaEnded=true, waiting for 0xFF confirm"); otaEnded = true; otaEndedAt = millis(); } otaReady = false; + Serial.printf("OTA: otaReady cleared — otaReady=%d, otaEnded=%d, otaConfirmed=%d, otaInProgress=%d\n", + otaReady, otaEnded, otaConfirmed, otaInProgress); } if (otaEnded && otaEarlyConfirm) { - ESP_LOGD(TAG, "OTA: processing deferred 0xFF confirm"); + Serial.println("OTA: processing deferred 0xFF confirm"); otaConfirmed = true; otaEarlyConfirm = false; } if (otaEnded && !otaConfirmed && (millis() - otaEndedAt > OTA_CONFIRM_TIMEOUT_MS)) { - ESP_LOGW(TAG, "OTA: 0xFF confirm timeout (%lu ms) — discarding update", - millis() - otaEndedAt); + Serial.printf("OTA: 0xFF confirm timeout (%lu ms) — discarding update, resuming normal operation\n", + millis() - otaEndedAt); otaReset(); } if (otaConfirmed) { - ESP_LOGI(TAG, "OTA: confirmed, setting boot partition"); + Serial.println("OTA: otaConfirmed=true, setting boot partition"); esp_err_t err = esp_ota_set_boot_partition(otaPartition); if (err != ESP_OK) { - ESP_LOGE(TAG, "OTA: set boot partition failed (%d)", err); + Serial.printf("OTA: set boot partition failed (%d)\n", err); } else { leds[0] = CRGB::Green; FastLED.show(); - ESP_LOGI(TAG, "OTA: done, rebooting..."); + Serial.println("OTA: done, rebooting..."); delay(500); esp_restart(); } @@ -637,7 +652,7 @@ void loop() { if (relay1State != lastRelay1 || relay2State != lastRelay2) { bool anyBle1 = (connActive[0] && bleRelay1[0]) || (connActive[1] && bleRelay1[1]); bool anyBle2 = (connActive[0] && bleRelay2[0]) || (connActive[1] && bleRelay2[1]); - ESP_LOGI(TAG, "Relays: R1=%s R2=%s (t1=%s t2=%s btn=%s ble1=%s ble2=%s)", + Serial.printf("Relays: R1=%s R2=%s (t1=%s t2=%s btn=%s ble1=%s ble2=%s)\n", relay1State ? "ON" : "OFF", relay2State ? "ON" : "OFF", t1Active ? "YES" : "no", @@ -653,7 +668,7 @@ void loop() { if (!otaInProgress && millis() - heartbeat > 60000) { bool anyBle1 = (connActive[0] && bleRelay1[0]) || (connActive[1] && bleRelay1[1]); bool anyBle2 = (connActive[0] && bleRelay2[0]) || (connActive[1] && bleRelay2[1]); - ESP_LOGD(TAG, "[heartbeat] R1=%s R2=%s t1=%s t2=%s btn=%s ble1=%s ble2=%s clients=%d", + Serial.printf("[heartbeat] R1=%s R2=%s t1=%s t2=%s btn=%s ble1=%s ble2=%s clients=%d\n", relay1State ? "ON" : "OFF", relay2State ? "ON" : "OFF", t1Active ? "YES" : "no",