-
Notifications
You must be signed in to change notification settings - Fork 554
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Delay() inside of "for" loops fail after socket connection is made #58
Comments
yes that is normal, when using async if you want delayed actions on way is to set a flag or save the executing time. may reading millis and comparing is working inside the webSocketEvent. until we port the ESP8266 RTOS SDK this is the only way. |
@Links2004, thanks for the quick reply. I used a flag as a workaround. My solution was similar to the code below. #include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <WebSocketsClient.h>
#include <Hash.h>
ESP8266WiFiMulti WiFiMulti;
WebSocketsClient webSocket;
boolean mustDoSomething = false;
void doSomething(){
// Now also works as expected
for(uint8_t c = 255; c > 0; c--) {
Serial.println(c);
delay(1000);
}
}
void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
mustDoSomething = true;
}
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() {
if (mustDoSomething){
doSomething();
}
mustDoSomething = false;
}
|
can we use HTTPS website with communicate |
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
The text was updated successfully, but these errors were encountered: