firmware: v10 — fix OTA ESP8266 memoria + idioma de pitidos

Fix OTA ESP8266 (pitidos cada arranque):
- BearSSL ocupa ~20KB de heap. El cliente de version.txt y el cliente
  de firmware.bin coexistian → sin heap suficiente → descarga falla.
- Ahora el primer cliente se destruye en su scope {} antes de crear
  el segundo. setBufferSizes(512,512) reduce uso BearSSL durante descarga.

Idioma de pitidos:
- 2 pitidos: handshake OK, ambas placas conectadas y listas
- 3 pitidos: ESP32-CAM actualizandose via OTA
- 4 pitidos: ESP8266 actualizandose via OTA

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Natxo1000
2026-06-02 14:49:11 +02:00
parent e02a805aa3
commit b9bd18a568
6 changed files with 51 additions and 40 deletions

View File

@@ -7,7 +7,7 @@
// ================================================================ // ================================================================
// OTA CONFIG // OTA CONFIG
// ================================================================ // ================================================================
#define FW_VERSION 9 #define FW_VERSION 10
#define GITEA_HOST "https://git.nacho.myds.me" #define GITEA_HOST "https://git.nacho.myds.me"
#define GITEA_OWNER "Natxo" #define GITEA_OWNER "Natxo"
#define GITEA_REPO "Arduino-Car" #define GITEA_REPO "Arduino-Car"
@@ -57,47 +57,53 @@ static void checkOTA() {
return; // sin WiFi, arranque normal 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 String base = String(GITEA_HOST) + "/" + GITEA_OWNER + "/" + GITEA_REPO
+ "/raw/branch/" + GITEA_BRANCH + "/firmware/esp8266/"; + "/raw/branch/" + GITEA_BRANCH + "/firmware/esp8266/";
String token = "?token=" + String(GITEA_TOKEN); String token = "?token=" + String(GITEA_TOKEN);
http.begin(client, base + "version.txt" + token); // ── Bloque de scope: libera el cliente BearSSL antes de la descarga ──
http.setTimeout(10000); // BearSSL ocupa ~20KB de heap. Si los dos clientes coexisten el heap
int code = http.GET(); // se agota y ESPhttpUpdate falla silenciosamente.
String body; int remoteVer = 0;
if (code == HTTP_CODE_OK) body = http.getString(); {
http.end(); BearSSL::WiFiClientSecure client;
client.setInsecure();
if (code == HTTP_CODE_OK) { client.setBufferSizes(512, 512); // buffers mínimos — suficiente para la respuesta
body.trim(); HTTPClient http;
int remoteVer = body.toInt(); http.begin(client, base + "version.txt" + token);
if (remoteVer > FW_VERSION) { http.setTimeout(10000);
// 4 pitidos = ESP8266 actualizando int code = http.GET();
pinMode(buzzerPin, OUTPUT); if (code == HTTP_CODE_OK) {
for (int i = 0; i < 4; i++) { String body = http.getString();
digitalWrite(buzzerPin, HIGH); body.trim();
delay(150); remoteVer = body.toInt();
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
} }
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(); WiFi.disconnect();
@@ -127,6 +133,11 @@ void waitForReady() {
delay(50); delay(50);
while (Serial.available()) Serial.read(); // flush post-handshake while (Serial.available()) Serial.read(); // flush post-handshake
espReady = true; 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; return;
} }
buf = ""; buf = "";

View File

@@ -10,7 +10,7 @@
// ================================================================ // ================================================================
// OTA CONFIG // OTA CONFIG
// ================================================================ // ================================================================
#define FW_VERSION 9 #define FW_VERSION 10
#define GITEA_HOST "https://git.nacho.myds.me" #define GITEA_HOST "https://git.nacho.myds.me"
#define GITEA_OWNER "Natxo" #define GITEA_OWNER "Natxo"
#define GITEA_REPO "Arduino-Car" #define GITEA_REPO "Arduino-Car"

Binary file not shown.

View File

@@ -1 +1 @@
9 10

Binary file not shown.

View File

@@ -1 +1 @@
9 10