Update 'arduino/D1LED'
parent
ecd0bdac27
commit
92dfcbf384
@ -0,0 +1,54 @@
|
||||
#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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue