En ESP32 / ESP8266, añadir un delay() (o código que bloquea durante mucho tiempo) afecta directamente al rendimiento y la estabilidad del Wi-Fi, debido a cómo funciona la pila Wi-Fi. Las esperas cortas (unos pocos ms) suelen ser seguras. Pero las esperas largas (> ~100 ms) pueden provocar timeouts del Wi-Fi, paquetes perdidos o desconexiones.
Si tienes algún delay(x); largo en la función loop(), es posible que tengas que reescribirlo para que no sea bloqueante.
Ejemplo (código incorrecto):
const int ledPin = 2;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
delay(5000) //!!!!!!!!!!! DO NOT DO THIS!!!!!!!!!
digitalWrite(ledPin, !digitalRead(ledPin));
}
Ejemplo (código correcto):
const int ledPin = 2;
// Variables to manage timing
unsigned long previousMillis = 0; // Stores last time LED was updated
const long interval = 1000; // Interval for blinking (milliseconds)
void setup() {
// Initialize the LED pin as an output
pinMode(ledPin, OUTPUT);
}
void loop() {
// Get the current time
unsigned long currentMillis = millis();
// Check if the interval has passed
if (currentMillis - previousMillis >= interval) {
// Save the current time
previousMillis = currentMillis;
// Toggle the LED state
digitalWrite(ledPin, !digitalRead(ledPin));
}
}
Si estás desarrollando con ESP32 o ESP8266 y notas un comportamiento errático del WiFi — como desconexiones frecuentes, señal débil o conexiones fallidas — puede que te hayas topado con una peculiaridad de hardware bien documentada: inestabilidad del WiFi cuando se usan los pines del conversor analógico-digital (ADC).
Tanto el ESP32 como el ESP8266 comparten recursos internos entre la radio WiFi y las operaciones del ADC. Cuando el ADC está muestreando activamente (sobre todo a alta frecuencia o con lecturas continuas), puede interferir con la circuitería de RF responsable de la comunicación WiFi. Esto provoca:
Este problema se nota especialmente al:
analogRead() con frecuencia y sin esperasAñade esperas entre las lecturas del ADC
Evita el sondeo continuo. Introduce pequeñas esperas (p. ej., delay(10) o vTaskDelay()) entre las lecturas analógicas para darle un respiro a la pila WiFi.
```cpp int sensorValue = analogRead(A0); delay(10); // Let WiFi recover
Try starting a hotspot from your mobile phone and then connect your ESP to SinricPro via the hotspot. If you can connect to SinricPro via the hotspot, then the problem is with your WiFi network.
Try switching to a different WiFi network if possible.
Always start by trying our example sketches, changing only the credentials. They have been thoroughly tested and are known to work correctly.
#define ENABLE_DEBUG to top of the sketch.* To enable ESP8266 logs, in Arduinio IDE:
1. `Tools -> Debug Serial Port -> Serial`
2. `Tools -> Debug Level -> SSL + HTTP_CLIENT`
* To enable ESP32 logs, in Arduinio IDE:
1. `Tools -> Core Debug Level -> Verbose`
Sometimes, due to memory limitations, the ESP chip may fail while trying to establish the SSL connection to the SinricPro server. In this case, you can try disabling the SSL feature by adding #define SINRICPRO_NOSSL to the top of the sketch (before #include “SinricPro.h”):
#define SINRICPRO_NOSSL
#include "SinricPro.h"
...
Si nada de lo anterior te funciona, revisa las incidencias existentes en el repositorio de GitHub o abre una nueva
Únete a SinricPro en Discord : https://discord.gg/CqjBrkM6