Closed
Description
Using the async branch, delay()
s inside of "for" loops aren't honored after a websockets connection is established. The same loop performs as expected before the ws connection is made. Is this expected behavior? Is there a workaround?
Hardware
Generic ESP-12E board
Sketch
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <WebSocketsClient.h>
#include <Hash.h>
ESP8266WiFiMulti WiFiMulti;
WebSocketsClient webSocket;
void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
// Immediately exits the for loop and prints 1-255 in the console
for(uint8_t c = 255; c > 0; c--) {
Serial.println(c);
delay(1000);
}
}
void setup() {
Serial.begin(115200);
WiFiMulti.addAP("myNetworkName", "myPassword");
while(WiFiMulti.run() != WL_CONNECTED) {
delay(100);
}
webSocket.begin("192.168.1.119", 1440);
webSocket.onEvent(webSocketEvent);
// Works as expected
for(uint8_t c = 255; c > 0; c--) {
Serial.println(c);
delay(1000);
}
}
void loop() {
}
Metadata
Metadata
Assignees
Labels
No labels