Skip to content

Instantly share code, notes, and snippets.

@uncletammy
Created March 4, 2016 16:48
Show Gist options
  • Save uncletammy/751128078b77c9f6d852 to your computer and use it in GitHub Desktop.
Save uncletammy/751128078b77c9f6d852 to your computer and use it in GitHub Desktop.
ESP8266 Delay in for loops - Websockets
#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(500);
}
}
void setup() {
Serial.begin(115200);
WiFiMulti.addAP("myNetworkName", "myPassword");
while(WiFiMulti.run() != WL_CONNECTED) {
delay(100);
}
webSocket.begin("192.168.1.119", 1440,"/",String(WiFi.macAddress()));
webSocket.onEvent(webSocketEvent);
// Works as expected
for(uint8_t c = 255; c > 0; c--) {
Serial.println(c);
delay(1000);
}
}
void loop() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment