From ecd0bdac2775a436a915b00d160279bae8d68a83 Mon Sep 17 00:00:00 2001 From: louisa Date: Thu, 15 Jun 2023 11:51:52 +0200 Subject: [PATCH 1/2] Add 'arduino/D1LED' --- arduino/D1LED | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 arduino/D1LED diff --git a/arduino/D1LED b/arduino/D1LED new file mode 100644 index 0000000..e69de29 From 92dfcbf3845139a7966981817b44f40246f8f84c Mon Sep 17 00:00:00 2001 From: louisa Date: Thu, 15 Jun 2023 11:51:58 +0200 Subject: [PATCH 2/2] Update 'arduino/D1LED' --- arduino/D1LED | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/arduino/D1LED b/arduino/D1LED index e69de29..4108647 100644 --- a/arduino/D1LED +++ b/arduino/D1LED @@ -0,0 +1,54 @@ +#include +#include + +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; + } +}