I have the following sketch:
Code: Select all
#include <WiFi.h>
#include <WebSocketsClient.h>
unsigned int timer;
void setup() {
pinMode(2, OUTPUT);
/* Connect Wifi Network */
WiFi.begin("SSID", "PASS");
/* Connect WebSocket Server */
webSocket.begin("ip", 2342, "/"); // Connect WebSocket Server
webSocket.onEvent(webSocketEvent); // Set WebSocket Event Function
webSocket.setReconnectInterval(5000); // Set WebSocket Reconnect Interval
}
void loop() {
webSocket.loop();
if((millis() - timer) >= 250) {
if(digitalRead(2) == LOW) {
digitalWrite(2, HIGH);
} else {
digitalWrite(2, LOW);
}
timer = millis();
}
}
void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
String payload_str = String((char*) payload);
const char* payload_set_str = payload_str.c_str();
switch(type) {
case WStype_CONNECTED:
break;
case WStype_TEXT:
break;
}
}