diff --git a/ESP8266/ESP8266.ino b/ESP8266/ESP8266.ino index 8c1c497..1cda0c8 100644 --- a/ESP8266/ESP8266.ino +++ b/ESP8266/ESP8266.ino @@ -7,7 +7,7 @@ // ================================================================ // OTA CONFIG // ================================================================ -#define FW_VERSION 9 +#define FW_VERSION 10 #define GITEA_HOST "https://git.nacho.myds.me" #define GITEA_OWNER "Natxo" #define GITEA_REPO "Arduino-Car" @@ -57,47 +57,53 @@ static void checkOTA() { return; // sin WiFi, arranque normal } - BearSSL::WiFiClientSecure client; - client.setInsecure(); // cert Let's Encrypt/autofirmado — OK para LAN privada - HTTPClient http; - String base = String(GITEA_HOST) + "/" + GITEA_OWNER + "/" + GITEA_REPO + "/raw/branch/" + GITEA_BRANCH + "/firmware/esp8266/"; String token = "?token=" + String(GITEA_TOKEN); - http.begin(client, base + "version.txt" + token); - http.setTimeout(10000); - int code = http.GET(); - String body; - if (code == HTTP_CODE_OK) body = http.getString(); - http.end(); - - if (code == HTTP_CODE_OK) { - body.trim(); - int remoteVer = body.toInt(); - if (remoteVer > FW_VERSION) { - // 4 pitidos = ESP8266 actualizando - pinMode(buzzerPin, OUTPUT); - for (int i = 0; i < 4; i++) { - digitalWrite(buzzerPin, HIGH); - delay(150); - digitalWrite(buzzerPin, LOW); - delay(150); - } - delay(300); - - // Fuerza pines de motor a LOW antes del flash para minimizar glitch de GPIO - analogWrite(ENA, 0); analogWrite(ENB, 0); - digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); - digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); - - BearSSL::WiFiClientSecure updateClient; - updateClient.setInsecure(); - ESPhttpUpdate.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS); - ESPhttpUpdate.rebootOnUpdate(true); - ESPhttpUpdate.update(updateClient, base + "firmware.bin" + token); - // Si llega aquí, el update falló — continúa arranque normal + // ── Bloque de scope: libera el cliente BearSSL antes de la descarga ── + // BearSSL ocupa ~20KB de heap. Si los dos clientes coexisten el heap + // se agota y ESPhttpUpdate falla silenciosamente. + int remoteVer = 0; + { + BearSSL::WiFiClientSecure client; + client.setInsecure(); + client.setBufferSizes(512, 512); // buffers mínimos — suficiente para la respuesta + HTTPClient http; + http.begin(client, base + "version.txt" + token); + http.setTimeout(10000); + int code = http.GET(); + if (code == HTTP_CODE_OK) { + String body = http.getString(); + body.trim(); + remoteVer = body.toInt(); } + http.end(); + } // ← client y http se destruyen aquí, ~20KB liberados + + if (remoteVer > FW_VERSION) { + // 4 pitidos = ESP8266 actualizando + pinMode(buzzerPin, OUTPUT); + for (int i = 0; i < 4; i++) { + digitalWrite(buzzerPin, HIGH); + delay(150); + digitalWrite(buzzerPin, LOW); + delay(150); + } + delay(300); + + // Fuerza pines de motor a LOW antes del flash para minimizar glitch de GPIO + analogWrite(ENA, 0); analogWrite(ENB, 0); + digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); + digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); + + BearSSL::WiFiClientSecure updateClient; + updateClient.setInsecure(); + updateClient.setBufferSizes(512, 512); // reduce heap BearSSL durante descarga + ESPhttpUpdate.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS); + ESPhttpUpdate.rebootOnUpdate(true); + ESPhttpUpdate.update(updateClient, base + "firmware.bin" + token); + // Si llega aquí, el update falló — continúa arranque normal } WiFi.disconnect(); @@ -127,6 +133,11 @@ void waitForReady() { delay(50); while (Serial.available()) Serial.read(); // flush post-handshake espReady = true; + // 2 pitidos: conexión entre placas establecida + for (int i = 0; i < 2; i++) { + digitalWrite(buzzerPin, HIGH); delay(100); + digitalWrite(buzzerPin, LOW); delay(100); + } return; } buf = ""; diff --git a/Esp32Cam/Esp32Cam.ino b/Esp32Cam/Esp32Cam.ino index 6b63424..7f1760b 100644 --- a/Esp32Cam/Esp32Cam.ino +++ b/Esp32Cam/Esp32Cam.ino @@ -10,7 +10,7 @@ // ================================================================ // OTA CONFIG // ================================================================ -#define FW_VERSION 9 +#define FW_VERSION 10 #define GITEA_HOST "https://git.nacho.myds.me" #define GITEA_OWNER "Natxo" #define GITEA_REPO "Arduino-Car" diff --git a/firmware/esp32cam/firmware.bin b/firmware/esp32cam/firmware.bin index 878e88c..77e9e99 100644 Binary files a/firmware/esp32cam/firmware.bin and b/firmware/esp32cam/firmware.bin differ diff --git a/firmware/esp32cam/version.txt b/firmware/esp32cam/version.txt index f11c82a..9a03714 100644 --- a/firmware/esp32cam/version.txt +++ b/firmware/esp32cam/version.txt @@ -1 +1 @@ -9 \ No newline at end of file +10 \ No newline at end of file diff --git a/firmware/esp8266/firmware.bin b/firmware/esp8266/firmware.bin index 9757547..8c0b436 100644 Binary files a/firmware/esp8266/firmware.bin and b/firmware/esp8266/firmware.bin differ diff --git a/firmware/esp8266/version.txt b/firmware/esp8266/version.txt index f11c82a..9a03714 100644 --- a/firmware/esp8266/version.txt +++ b/firmware/esp8266/version.txt @@ -1 +1 @@ -9 \ No newline at end of file +10 \ No newline at end of file