Skip to content

Delay() inside of "for" loops fail after socket connection is made #58

@uncletammy

Description

@uncletammy

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy