firmware: v18 — fix bug critico espReady + watchdog ESP8266
Bug: en v16 se elimino if(!espReady)return del loop() y no se restauro en v17. Resultado: bytes basura del bootloader ESP32 (ej 0x42='B') se ejecutaban como backward() antes y despues del handshake. Fixes: - Restaurado bool espReady con guard if(!espReady)return en loop() - Restaurado handler 'G' en loop() para reinicio del ESP32: espReady=false + stopMotors() inmediato + nuevo handshake - Watchdog ligero en ESP8266 (solo millis(), sin FreeRTOS): si no llega comando de movimiento en 1.5s -> para motores Evita que el coche siga moviendose si el ESP32 crashea Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
// ================================================================
|
||||
// OTA CONFIG
|
||||
// ================================================================
|
||||
#define FW_VERSION 17
|
||||
#define FW_VERSION 18
|
||||
#define GITEA_HOST "https://git.nacho.myds.me"
|
||||
#define GITEA_OWNER "Natxo"
|
||||
#define GITEA_REPO "Arduino-Car"
|
||||
@@ -110,6 +110,8 @@ static void checkOTA() {
|
||||
WiFi.mode(WIFI_OFF); // apaga radio para ahorrar energía
|
||||
}
|
||||
|
||||
bool espReady = false;
|
||||
|
||||
void waitForReady() {
|
||||
delay(300);
|
||||
while (Serial.available()) Serial.read();
|
||||
@@ -124,6 +126,7 @@ void waitForReady() {
|
||||
Serial.print("OK\n");
|
||||
delay(50);
|
||||
while (Serial.available()) Serial.read();
|
||||
espReady = true;
|
||||
// 2 pitidos: conexión entre placas lista
|
||||
for (int i = 0; i < 2; i++) {
|
||||
digitalWrite(buzzerPin, HIGH); delay(180);
|
||||
@@ -138,6 +141,7 @@ void waitForReady() {
|
||||
}
|
||||
delay(10);
|
||||
}
|
||||
espReady = true; // timeout: arranca igualmente
|
||||
}
|
||||
|
||||
void setup() {
|
||||
@@ -166,15 +170,42 @@ void setup() {
|
||||
waitForReady();
|
||||
}
|
||||
|
||||
// Watchdog ligero en ESP8266: si no llega comando de movimiento en 1.5s → para
|
||||
// Evita que el coche siga moviéndose si el ESP32 se cuelga o reinicia
|
||||
unsigned long lastMoveMs = 0;
|
||||
bool motorRunning = false;
|
||||
|
||||
void loop() {
|
||||
// Watchdog: sin comandos durante 1.5s → para motores
|
||||
if (motorRunning && (millis() - lastMoveMs > 1500)) {
|
||||
stopMotors();
|
||||
motorRunning = false;
|
||||
}
|
||||
|
||||
if (Serial.available()) {
|
||||
char c = Serial.read();
|
||||
|
||||
if (c == 'F') forward();
|
||||
else if (c == 'B') backward();
|
||||
else if (c == 'L') left();
|
||||
else if (c == 'R') right();
|
||||
else if (c == 'S') stopMotors();
|
||||
// Reinicio del ESP32-CAM: manda "GO\n" de nuevo
|
||||
if (c == 'G') {
|
||||
espReady = false;
|
||||
stopMotors();
|
||||
motorRunning = false;
|
||||
Serial.readStringUntil('\n');
|
||||
Serial.print("OK\n");
|
||||
delay(50);
|
||||
while (Serial.available()) Serial.read();
|
||||
espReady = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignorar todo hasta que el handshake esté completo
|
||||
if (!espReady) return;
|
||||
|
||||
if (c == 'F') { forward(); lastMoveMs = millis(); motorRunning = true; }
|
||||
else if (c == 'B') { backward(); lastMoveMs = millis(); motorRunning = true; }
|
||||
else if (c == 'L') { left(); lastMoveMs = millis(); motorRunning = true; }
|
||||
else if (c == 'R') { right(); lastMoveMs = millis(); motorRunning = true; }
|
||||
else if (c == 'S') { stopMotors(); motorRunning = false; }
|
||||
|
||||
else if (c == 'V') {
|
||||
int val = Serial.parseInt();
|
||||
|
||||
Reference in New Issue
Block a user