firmware: v16 — sin watchdog ni handshake (prueba simplificada)
Eliminados para diagnostico del problema de ruido electrico: - Watchdog de motores (tarea FreeRTOS en ESP32) - Handshake GO/OK bidireccional - ESP8266 vuelve a delay fijo de 15s para esperar al ESP32 Si el problema de desconexion persiste con v16 -> es hardware (ruido L298N) Si mejora -> alguna de estas tareas contribuia al problema Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
// ================================================================
|
||||
// OTA CONFIG
|
||||
// ================================================================
|
||||
#define FW_VERSION 13
|
||||
#define FW_VERSION 16
|
||||
#define GITEA_HOST "https://git.nacho.myds.me"
|
||||
#define GITEA_OWNER "Natxo"
|
||||
#define GITEA_REPO "Arduino-Car"
|
||||
@@ -110,45 +110,6 @@ static void checkOTA() {
|
||||
WiFi.mode(WIFI_OFF); // apaga radio para ahorrar energía
|
||||
}
|
||||
|
||||
bool espReady = false;
|
||||
|
||||
// ── Handshake con ESP32-CAM ──────────────────────────────────────
|
||||
// Descarta basura del bootloader ROM (115200 baud → bytes aleatorios),
|
||||
// luego espera exactamente "GO\n" y responde "OK\n".
|
||||
void waitForReady() {
|
||||
// Descarta todo lo que haya en el buffer (logs de arranque del ESP32)
|
||||
delay(300);
|
||||
while (Serial.available()) Serial.read();
|
||||
|
||||
// Espera "GO\n" del ESP32-CAM (máx 90s por si está haciendo OTA)
|
||||
unsigned long timeout = millis() + 90000UL;
|
||||
String buf = "";
|
||||
while (millis() < timeout) {
|
||||
while (Serial.available()) {
|
||||
char c = Serial.read();
|
||||
if (c == '\n') {
|
||||
buf.trim();
|
||||
if (buf == "GO") {
|
||||
Serial.print("OK\n");
|
||||
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(180);
|
||||
digitalWrite(buzzerPin, LOW); delay(180);
|
||||
}
|
||||
return;
|
||||
}
|
||||
buf = "";
|
||||
} else if (c != '\r') {
|
||||
if (buf.length() < 8) buf += c;
|
||||
}
|
||||
}
|
||||
delay(10);
|
||||
}
|
||||
espReady = true; // timeout: arranca igual
|
||||
}
|
||||
|
||||
void setup() {
|
||||
// 1. Pines y parada inmediata
|
||||
@@ -172,27 +133,15 @@ void setup() {
|
||||
servoX.write(posX);
|
||||
servoY.write(posY);
|
||||
|
||||
// 5. Esperar señal '!' del ESP32-CAM antes de procesar comandos
|
||||
waitForReady();
|
||||
// 5. Esperar a que el ESP32-CAM termine de arrancar
|
||||
unsigned long elapsed = millis();
|
||||
if (elapsed < 15000) delay(15000 - elapsed);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (Serial.available()) {
|
||||
char c = Serial.read();
|
||||
|
||||
// Detecta re-arranque del ESP32-CAM: envía "GO\n" de nuevo
|
||||
if (c == 'G') {
|
||||
Serial.readStringUntil('\n'); // consume "O\n"
|
||||
Serial.print("OK\n");
|
||||
delay(50);
|
||||
while (Serial.available()) Serial.read();
|
||||
espReady = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignorar todo hasta completar el handshake
|
||||
if (!espReady) return;
|
||||
|
||||
if (c == 'F') forward();
|
||||
else if (c == 'B') backward();
|
||||
else if (c == 'L') left();
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// ================================================================
|
||||
// OTA CONFIG
|
||||
// ================================================================
|
||||
#define FW_VERSION 15
|
||||
#define FW_VERSION 16
|
||||
#define GITEA_HOST "https://git.nacho.myds.me"
|
||||
#define GITEA_OWNER "Natxo"
|
||||
#define GITEA_REPO "Arduino-Car"
|
||||
@@ -24,31 +24,6 @@ const char *password = "Suprak1llm1ndS23S";
|
||||
void startCameraServer();
|
||||
void setupLedFlash();
|
||||
|
||||
// ── Handshake bidireccional — tarea FreeRTOS (no bloquea setup) ─
|
||||
// Corre en paralelo con el servidor web. Envía "GO\n" cada 300ms
|
||||
// hasta recibir "OK\n" o agotar 30s.
|
||||
static void handshakeTask(void *) {
|
||||
unsigned long deadline = millis() + 30000UL;
|
||||
String buf = "";
|
||||
while (millis() < deadline) {
|
||||
Serial.print("GO\n");
|
||||
unsigned long t = millis();
|
||||
while (millis() - t < 300) {
|
||||
while (Serial.available()) {
|
||||
char c = Serial.read();
|
||||
if (c == '\n') {
|
||||
buf.trim();
|
||||
if (buf == "OK") { vTaskDelete(NULL); return; }
|
||||
buf = "";
|
||||
} else if (c != '\r' && buf.length() < 8) {
|
||||
buf += c;
|
||||
}
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(5));
|
||||
}
|
||||
}
|
||||
vTaskDelete(NULL); // timeout
|
||||
}
|
||||
|
||||
// ── OTA: comprueba si hay firmware nuevo y actualiza si hace falta ──
|
||||
static void checkOTA() {
|
||||
@@ -172,9 +147,6 @@ void setup() {
|
||||
|
||||
// ── Servidor cámara ───────────────────────────────────────────────
|
||||
startCameraServer();
|
||||
|
||||
// Handshake en tarea separada — no bloquea setup() ni el watchdog
|
||||
xTaskCreate(handshakeTask, "handshake", 4096, NULL, 1, NULL);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
@@ -48,21 +48,6 @@ static const char *_STREAM_PART = "Content-Type: image/jpeg\r\nContent-Length: %
|
||||
httpd_handle_t stream_httpd = NULL;
|
||||
httpd_handle_t camera_httpd = NULL;
|
||||
|
||||
// ── Watchdog de motores ────────────────────────────────────────────
|
||||
// Si no llega ningún comando de movimiento en 400ms → para automáticamente
|
||||
static volatile bool motorMoving = false;
|
||||
static volatile int64_t lastMoveCmdUs = 0;
|
||||
#define WATCHDOG_US 800000LL // 800ms — se retroalimenta con heartbeat JS cada 150ms
|
||||
|
||||
static void motorWatchdogTask(void *) {
|
||||
while (1) {
|
||||
if (motorMoving && (esp_timer_get_time() - lastMoveCmdUs) > WATCHDOG_US) {
|
||||
Serial.print("S\n");
|
||||
motorMoving = false;
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(80));
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
size_t size; //number of values used for filtering
|
||||
@@ -371,16 +356,6 @@ static esp_err_t cmd_handler(httpd_req_t *req) {
|
||||
} else {
|
||||
Serial.printf("%s\n", value);
|
||||
}
|
||||
// Watchdog: registra comandos de movimiento
|
||||
if (!strcmp(variable, "car")) {
|
||||
char c = value[0];
|
||||
if (c=='F' || c=='B' || c=='L' || c=='R') {
|
||||
motorMoving = true;
|
||||
lastMoveCmdUs = esp_timer_get_time();
|
||||
} else if (c == 'S') {
|
||||
motorMoving = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (res < 0) {
|
||||
@@ -809,7 +784,6 @@ void startCameraServer() {
|
||||
httpd_register_uri_handler(stream_httpd, &stream_uri);
|
||||
}
|
||||
|
||||
xTaskCreate(motorWatchdogTask, "motorWD", 2048, NULL, 1, NULL);
|
||||
}
|
||||
|
||||
void setupLedFlash() {
|
||||
|
||||
Binary file not shown.
@@ -1 +1 @@
|
||||
15
|
||||
16
|
||||
Binary file not shown.
@@ -1 +1 @@
|
||||
13
|
||||
16
|
||||
Reference in New Issue
Block a user