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:
@@ -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 = "";
|
||||
|
||||
Reference in New Issue
Block a user