You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.4 KiB
Plaintext

#include <ESP8266WiFi.h>
#include <WebSocketsClient.h>
const char* ssid = "Ether Axis";
const char* password = "WanderingWebWizard";
WebSocketsClient webSocket;
void setup() {
// Initialize the serial communication
Serial.begin(9600);
// Connect to Wi-Fi network
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi!");
// Set up event handlers
webSocket.onEvent(onWebSocketEvent);
// Connect to the WebSocket server
webSocket.begin("192.168.2.1", 8000, "/socket.io/?transport=websocket");
}
void loop() {
// Maintain the WebSocket connection
webSocket.loop();
}
void onWebSocketEvent(WStype_t type, uint8_t* payload, size_t length) {
switch (type) {
case WStype_DISCONNECTED:
Serial.println("[WebSocket] Disconnected!");
break;
case WStype_CONNECTED:
Serial.println("[WebSocket] Connected!");
break;
case WStype_TEXT:
Serial.println("[WebSocket] Text received!");
Serial.write(payload, length);
// Check if the received message is the "blink" event
if (strncmp((const char*)payload, "blink", length) == 0) {
// Perform the desired action for the "blink" event
Serial.println("Received blink event!");
// Add your code here to trigger the blink action
}
break;
}
}