Merge branch 'fix/issue-5-hs-s43a-s3r-cleanup'

This commit is contained in:
eddy 2026-08-02 00:53:03 +02:00
commit 109088cf52
13 changed files with 511 additions and 48 deletions

View file

@ -217,8 +217,8 @@ void setup() {
allProvisioned = keyProvisioned && uuidProvisioned && serverProvisioned;
pinMode(TOUCH1_PIN, INPUT_PULLUP);
pinMode(TOUCH2_PIN, INPUT_PULLUP);
pinMode(TOUCH1_PIN, INPUT);
pinMode(TOUCH2_PIN, INPUT);
pinMode(BUTTON_PIN, INPUT);
if (allProvisioned) {
@ -346,8 +346,8 @@ void loop() {
static uint32_t t1Change = 0;
static uint32_t t2Change = 0;
static uint32_t btnChange = 0;
bool t1Raw = (digitalRead(TOUCH1_PIN) == LOW);
bool t2Raw = (digitalRead(TOUCH2_PIN) == LOW);
bool t1Raw = (digitalRead(TOUCH1_PIN) == HIGH);
bool t2Raw = (digitalRead(TOUCH2_PIN) == HIGH);
bool btnRaw = (digitalRead(BUTTON_PIN) == LOW);
if (t1Raw != t1Stable) { t1Change = millis(); t1Stable = t1Raw; }
if (t2Raw != t2Stable) { t2Change = millis(); t2Stable = t2Raw; }

View file

@ -205,7 +205,10 @@ static void sendOtaNotify(NimBLECharacteristic *otaChar, uint8_t status, uint32_
buf[3] = (seq >> 8) & 0xFF;
buf[4] = seq & 0xFF;
otaChar->setValue(buf, 5);
otaChar->notify();
bool ok = otaChar->notify();
if (!ok) {
Serial.printf("OTA: notify() returned false for status=0x%02X seq=%lu\n", status, seq);
}
}
static void abortOta(NimBLECharacteristic *otaChar, const char *reason) {
@ -224,6 +227,13 @@ class OtaCharacteristicCallbacks : public NimBLECharacteristicCallbacks {
const uint8_t *data = (const uint8_t *)value.data();
size_t len = value.length();
if (otaWaitingForReboot && len == 1 && data[0] == 0xFF) {
otaWaitingForReboot = false;
otaConfirmed = true;
Serial.println("OTA: reboot confirmation received");
return;
}
if (len == 5 && data[0] == OTA_CMD_START) {
if (otaInProgress) {
esp_ota_end(otaHandle);
@ -306,7 +316,10 @@ 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) {
Serial.printf("OTA: write err at seq %lu (%d)\n", seq, err);
sendOtaNotify(pChar, OTA_STATUS_NAK, seq);
@ -399,8 +412,8 @@ void setup() {
Serial.println();
}
pinMode(TOUCH1_PIN, INPUT_PULLUP);
pinMode(TOUCH2_PIN, INPUT_PULLUP);
pinMode(TOUCH1_PIN, INPUT);
pinMode(TOUCH2_PIN, INPUT);
pinMode(BUTTON_PIN, INPUT);
pinMode(RELAY1_PIN, OUTPUT);
pinMode(RELAY2_PIN, OUTPUT);
@ -476,6 +489,26 @@ void setup() {
}
void loop() {
if (otaWaitingForReboot) {
if (millis() - otaRebootWaitStart > 10000) {
Serial.println("OTA: no confirmation after 10s, rebooting anyway");
otaWaitingForReboot = false;
otaConfirmed = true;
}
delay(10);
return;
}
if (otaConfirmed) {
otaConfirmed = false;
esp_err_t err = esp_ota_set_boot_partition(otaPartition);
if (err != ESP_OK) {
Serial.printf("OTA: set boot partition failed (%d)\n", err);
}
delay(100);
esp_restart();
return;
}
if (!otaInProgress && Serial.available()) {
static String serialBuf;
char c = Serial.read();
@ -580,8 +613,8 @@ void loop() {
static uint32_t t2Change = 0;
static uint32_t btnChange = 0;
#define DEBOUNCE_MS 50
bool t1Raw = (digitalRead(TOUCH1_PIN) == LOW);
bool t2Raw = (digitalRead(TOUCH2_PIN) == LOW);
bool t1Raw = (digitalRead(TOUCH1_PIN) == HIGH);
bool t2Raw = (digitalRead(TOUCH2_PIN) == HIGH);
bool btnRaw = (digitalRead(BUTTON_PIN) == LOW);
if (t1Raw != t1Stable) { t1Change = millis(); t1Stable = t1Raw; }
if (t2Raw != t2Stable) { t2Change = millis(); t2Stable = t2Raw; }