firmware: v8 — handshake GO/OK bidireccional

Problema raiz: el bootloader ROM del ESP32 emite logs a 115200 baud.
Al recibirlos a 9600 baud en el ESP8266 salen bytes aleatorios, alguno
de los cuales puede ser F/B/L/R (mover ruedas) o '!' (activar espReady).

Solucion: handshake con string de 2 chars "GO\n" / "OK\n":
- ESP32-CAM envia "GO\n" cada 300ms hasta recibir "OK\n"
- ESP8266 descarta todo el buffer al arrancar (basura del bootloader),
  luego espera exactamente "GO\n" y responde "OK\n"
- En loop(), si ESP32 reinicia y manda "G", el ESP8266 repite el handshake
- Probabilidad de falso positivo: << 1 en millones vs ~40% del '!' solo

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Natxo1000
2026-06-02 13:31:33 +02:00
parent 1688cdb185
commit 7707953d4d
6 changed files with 61 additions and 16 deletions

View File

@@ -10,7 +10,7 @@
// ================================================================
// OTA CONFIG
// ================================================================
#define FW_VERSION 7
#define FW_VERSION 8
#define GITEA_HOST "https://git.nacho.myds.me"
#define GITEA_OWNER "Natxo"
#define GITEA_REPO "Arduino-Car"
@@ -24,6 +24,26 @@ const char *password = "Suprak1llm1ndS23S";
void startCameraServer();
void setupLedFlash();
// ── Handshake bidireccional con ESP8266 ─────────────────────────
// Envía "GO\n" cada 300ms hasta recibir "OK\n".
// Protege contra basura del bootloader ROM (115200 baud → bytes aleatorios).
static void handshakeEsp8266() {
unsigned long deadline = millis() + 30000UL; // máx 30s
while (millis() < deadline) {
Serial.print("GO\n");
unsigned long t = millis();
while (millis() - t < 300) {
if (Serial.available()) {
String resp = Serial.readStringUntil('\n');
resp.trim();
if (resp == "OK") return;
}
delay(5);
}
}
// Timeout: continúa sin confirmación
}
// ── OTA: comprueba si hay firmware nuevo y actualiza si hace falta ──
static void checkOTA() {
WiFiClientSecure client;
@@ -147,9 +167,8 @@ void setup() {
// ── Servidor cámara ───────────────────────────────────────────────
startCameraServer();
// Señal al ESP8266: estoy listo, puede empezar a procesar comandos
delay(200);
Serial.print("!");
// Handshake bidireccional: espera ACK del ESP8266
handshakeEsp8266();
}
void loop() {