diff --git a/examples/Generic/WiFiNINA/Generic_WebSocketClientSocketIO_WiFiNINA/Generic_WebSocketClientSocketIO_WiFiNINA.ino b/examples/Generic/WiFiNINA/Generic_WebSocketClientSocketIO_WiFiNINA/Generic_WebSocketClientSocketIO_WiFiNINA.ino index a0847364..d0ed4e20 100644 --- a/examples/Generic/WiFiNINA/Generic_WebSocketClientSocketIO_WiFiNINA/Generic_WebSocketClientSocketIO_WiFiNINA.ino +++ b/examples/Generic/WiFiNINA/Generic_WebSocketClientSocketIO_WiFiNINA/Generic_WebSocketClientSocketIO_WiFiNINA.ino @@ -38,8 +38,8 @@ SocketIOclient socketIO; IPAddress clientIP(192, 168, 2, 225); // Select the IP address according to your local network -IPAddress serverIP(192, 168, 2, 51); -uint16_t serverPort = 3000; +IPAddress serverIP(192, 168, 2, 30); +uint16_t serverPort = 8080; int status = WL_IDLE_STATUS; @@ -127,7 +127,6 @@ void printWifiStatus() Serial.println(" dBm"); } - void setup() { // Serial.begin(921600); @@ -137,16 +136,6 @@ void setup() Serial.print("\nStart Generic_WebSocketClientSocketIO_WiFiNINA on "); Serial.println(BOARD_NAME); Serial.println(WEBSOCKETS_GENERIC_VERSION); - Serial.println("Used/default SPI pinout:"); - Serial.print("MOSI:"); - Serial.println(MOSI); - Serial.print("MISO:"); - Serial.println(MISO); - Serial.print("SCK:"); - Serial.println(SCK); - Serial.print("SS:"); - Serial.println(SS); - // check for the WiFi module: if (WiFi.status() == WL_NO_MODULE) { diff --git a/examples/RP2040W/WebSocketClientSSL_RP2040W/WebSocketClientSSL_RP2040W.ino b/examples/RP2040W/WebSocketClientSSL_RP2040W/WebSocketClientSSL_RP2040W.ino new file mode 100644 index 00000000..1712e5a2 --- /dev/null +++ b/examples/RP2040W/WebSocketClientSSL_RP2040W/WebSocketClientSSL_RP2040W.ino @@ -0,0 +1,188 @@ +/**************************************************************************************************************************** + WebSocketClient_RP2040W.ino + For RP2040W boards using CYC43439 WiFi + + Blynk_WiFiNINA_WM is a library for the Mega, Teensy, SAM DUE, nRF52, STM32 and SAMD boards + (https://github.com/khoih-prog/Blynk_WiFiNINA_WM) to enable easy configuration/reconfiguration and + autoconnect/autoreconnect of WiFiNINA/Blynk + + Based on and modified from WebSockets libarary https://github.com/Links2004/arduinoWebSockets + to support other boards such as SAMD21, SAMD51, Adafruit's nRF52 boards, etc. + + Built by Khoi Hoang https://github.com/khoih-prog/WebSockets_Generic + Licensed under MIT license + + Created on: 24.05.2015 + Author: Markus Sattler + *****************************************************************************************************************************/ + +#if ( defined(ARDUINO_RASPBERRY_PI_PICO_W) ) + #if defined(WEBSOCKETS_NETWORK_TYPE) + #undef WEBSOCKETS_NETWORK_TYPE + #endif + #define WEBSOCKETS_NETWORK_TYPE NETWORK_RP2040W_WIFI +#else + #error This code is intended to run only on the RP2040W boards ! Please check your Tools->Board setting. +#endif + +#define _WEBSOCKETS_LOGLEVEL_ 2 + +#include + +#include + +WebSocketsClient webSocket; + +int status = WL_IDLE_STATUS; + +// Deprecated echo.websocket.org to be replaced +#define WS_SERVER "wss://echo.websocket.org" +#define SSL_PORT 443 + +///////please enter your sensitive data in the Secret tab/arduino_secrets.h + +char ssid[] = "your_ssid"; // your network SSID (name) +char pass[] = "12345678"; // your network password (use for WPA, or use as key for WEP), length must be 8+ + +bool alreadyConnected = false; + +void webSocketEvent(const WStype_t& type, uint8_t * payload, const size_t& length) +{ + switch (type) + { + case WStype_DISCONNECTED: + if (alreadyConnected) + { + Serial.println("[WSc] Disconnected!"); + alreadyConnected = false; + } + + break; + + case WStype_CONNECTED: + { + alreadyConnected = true; + + Serial.print("[WSc] Connected to url: "); + Serial.println((char *) payload); + + // send message to server when Connected + webSocket.sendTXT("Connected"); + } + + break; + + case WStype_TEXT: + Serial.print("[WSc] get text: "); + Serial.println((char *) payload); + + // send message to server + webSocket.sendTXT("message here"); + + break; + + case WStype_BIN: + Serial.print("[WSc] get binary length: "); + Serial.println(length); + + // KH, To check + // hexdump(payload, length); + + // send data to server + webSocket.sendBIN(payload, length); + + break; + + case WStype_PING: + // pong will be send automatically + Serial.println("[WSc] get ping"); + + break; + + case WStype_PONG: + // answer to a ping we send + Serial.println("[WSc] get pong"); + + break; + + default: + break; + } +} + +void printWifiStatus() +{ + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("WebSockets Client IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} + +void setup() +{ + //Initialize serial and wait for port to open: + Serial.begin(115200); + while (!Serial); + + Serial.print("\nStart WebSocketClientSSL_RP2040W on "); Serial.println(BOARD_NAME); + Serial.println(WEBSOCKETS_GENERIC_VERSION); + + /////////////////////////////////// + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) + { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + Serial.print(F("Connecting to SSID: ")); + Serial.println(ssid); + + status = WiFi.begin(ssid, pass); + + delay(1000); + + // attempt to connect to WiFi network + while ( status != WL_CONNECTED) + { + delay(500); + + // Connect to WPA/WPA2 network + status = WiFi.status(); + } + + printWifiStatus(); + + /////////////////////////////////// + + // server address, port and URL + Serial.print("WebSockets Server : "); + Serial.println(WS_SERVER); + + // server address, port and URL + webSocket.beginSSL(WS_SERVER, SSL_PORT); + + // event handler + webSocket.onEvent(webSocketEvent); + + // server address, port and URL + Serial.print("Connecting to WebSockets Server @ "); + Serial.println(WS_SERVER); +} + +void loop() +{ + webSocket.loop(); +} diff --git a/examples/RP2040W/WebSocketClientSocketIO_RP2040W/WebSocketClientSocketIO_RP2040W.ino b/examples/RP2040W/WebSocketClientSocketIO_RP2040W/WebSocketClientSocketIO_RP2040W.ino new file mode 100644 index 00000000..0fa94c2d --- /dev/null +++ b/examples/RP2040W/WebSocketClientSocketIO_RP2040W/WebSocketClientSocketIO_RP2040W.ino @@ -0,0 +1,243 @@ +/**************************************************************************************************************************** + WebSocketClientSocketIO_RP2040W.ino + For RP2040W boards using CYC43439 WiFi + + Blynk_WiFiNINA_WM is a library for the Mega, Teensy, SAM DUE, nRF52, STM32 and SAMD boards + (https://github.com/khoih-prog/Blynk_WiFiNINA_WM) to enable easy configuration/reconfiguration and + autoconnect/autoreconnect of WiFiNINA/Blynk + + Based on and modified from WebSockets libarary https://github.com/Links2004/arduinoWebSockets + to support other boards such as SAMD21, SAMD51, Adafruit's nRF52 boards, etc. + + Built by Khoi Hoang https://github.com/khoih-prog/WebSockets_Generic + Licensed under MIT license + + Created on: 24.05.2015 + Author: Markus Sattler + *****************************************************************************************************************************/ + +#if ( defined(ARDUINO_RASPBERRY_PI_PICO_W) ) + #if defined(WEBSOCKETS_NETWORK_TYPE) + #undef WEBSOCKETS_NETWORK_TYPE + #endif + #define WEBSOCKETS_NETWORK_TYPE NETWORK_RP2040W_WIFI +#else + #error This code is intended to run only on the RP2040W boards ! Please check your Tools->Board setting. +#endif + +#define _WEBSOCKETS_LOGLEVEL_ 2 + +////////////////////////////// +// New in v2.16.0 +#define SIO_PING_INTERVAL 90000L +#define SIO_PONG_TIMEOUT 120000L +#define SIO_DISCONNECT_TIMEOUT_COUNT 10 + +////////////////////////////// + +#include + +#include + +#include +#include + +SocketIOclient socketIO; + +int status = WL_IDLE_STATUS; + +// Select the IP address according to your local network +IPAddress clientIP(192, 168, 2, 225); + +// Select the IP address according to your local network +IPAddress serverIP(192, 168, 2, 30); +uint16_t serverPort = 8080; + +///////please enter your sensitive data in the Secret tab/arduino_secrets.h + +char ssid[] = "your_ssid"; // your network SSID (name) +char pass[] = "12345678"; // your network password (use for WPA, or use as key for WEP), length must be 8+ + +void socketIOEvent(const socketIOmessageType_t& type, uint8_t * payload, const size_t& length) +{ + switch (type) + { + case sIOtype_DISCONNECT: + Serial.println("[IOc] Disconnected"); + + break; + + case sIOtype_CONNECT: + Serial.print("[IOc] Connected to url: "); + Serial.println((char*) payload); + + // join default namespace (no auto join in Socket.IO V3) + socketIO.send(sIOtype_CONNECT, "/"); + + break; + + case sIOtype_EVENT: + Serial.print("[IOc] Get event: "); + Serial.println((char*) payload); + + break; + + case sIOtype_ACK: + Serial.print("[IOc] Get ack: "); + Serial.println(length); + + //hexdump(payload, length); + + break; + + case sIOtype_ERROR: + Serial.print("[IOc] Get error: "); + Serial.println(length); + + //hexdump(payload, length); + + break; + + case sIOtype_BINARY_EVENT: + Serial.print("[IOc] Get binary: "); + Serial.println(length); + + //hexdump(payload, length); + + break; + + case sIOtype_BINARY_ACK: + Serial.print("[IOc] Get binary ack: "); + Serial.println(length); + + //hexdump(payload, length); + + break; + + case sIOtype_PING: + Serial.println("[IOc] Get PING"); + + break; + + case sIOtype_PONG: + Serial.println("[IOc] Get PONG"); + + break; + + default: + break; + } +} + +void printWifiStatus() +{ + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("WebSockets Client IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} + +void setup() +{ + //Initialize serial and wait for port to open: + Serial.begin(115200); + while (!Serial); + + Serial.print("\nStart WebSocketClientSocketIO_RP2040W on "); Serial.println(BOARD_NAME); + Serial.println(WEBSOCKETS_GENERIC_VERSION); + + /////////////////////////////////// + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) + { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + Serial.print(F("Connecting to SSID: ")); + Serial.println(ssid); + + status = WiFi.begin(ssid, pass); + + delay(1000); + + // attempt to connect to WiFi network + while ( status != WL_CONNECTED) + { + delay(500); + + // Connect to WPA/WPA2 network + status = WiFi.status(); + } + + printWifiStatus(); + + /////////////////////////////////// + + // server address, port and URL + Serial.print("Connecting to WebSockets Server @ IP address: "); + Serial.print(serverIP); + Serial.print(", port: "); + Serial.println(serverPort); + + // setReconnectInterval to 10s, new from v2.5.1 to avoid flooding server. Default is 0.5s + socketIO.setReconnectInterval(10000); + + socketIO.setExtraHeaders("Authorization: 1234567890"); + + // server address, port and URL + // void begin(IPAddress host, uint16_t port, String url = "/socket.io/?EIO=4", String protocol = "arduino"); + // To use default EIO=4 from v2.5.1 + socketIO.begin(serverIP, serverPort); + + // event handler + socketIO.onEvent(socketIOEvent); +} + +unsigned long messageTimestamp = 0; + +void loop() +{ + socketIO.loop(); + + uint64_t now = millis(); + + if (now - messageTimestamp > 30000) + { + messageTimestamp = now; + + // creat JSON message for Socket.IO (event) + DynamicJsonDocument doc(1024); + JsonArray array = doc.to(); + + // add evnet name + // Hint: socket.on('event_name', .... + array.add("event_name"); + + // add payload (parameters) for the event + JsonObject param1 = array.createNestedObject(); + param1["now"] = (uint32_t) now; + + // JSON to String (serializion) + String output; + serializeJson(doc, output); + + // Send event + socketIO.sendEVENT(output); + + // Print JSON for debugging + Serial.println(output); + } +} diff --git a/examples/RP2040W/WebSocketClient_RP2040W/WebSocketClient_RP2040W.ino b/examples/RP2040W/WebSocketClient_RP2040W/WebSocketClient_RP2040W.ino new file mode 100644 index 00000000..104564d0 --- /dev/null +++ b/examples/RP2040W/WebSocketClient_RP2040W/WebSocketClient_RP2040W.ino @@ -0,0 +1,200 @@ +/**************************************************************************************************************************** + WebSocketClient_RP2040W.ino + For RP2040W boards using CYC43439 WiFi + + Blynk_WiFiNINA_WM is a library for the Mega, Teensy, SAM DUE, nRF52, STM32 and SAMD boards + (https://github.com/khoih-prog/Blynk_WiFiNINA_WM) to enable easy configuration/reconfiguration and + autoconnect/autoreconnect of WiFiNINA/Blynk + + Based on and modified from WebSockets libarary https://github.com/Links2004/arduinoWebSockets + to support other boards such as SAMD21, SAMD51, Adafruit's nRF52 boards, etc. + + Built by Khoi Hoang https://github.com/khoih-prog/WebSockets_Generic + Licensed under MIT license + + Created on: 24.05.2015 + Author: Markus Sattler + *****************************************************************************************************************************/ + +#if ( defined(ARDUINO_RASPBERRY_PI_PICO_W) ) + #if defined(WEBSOCKETS_NETWORK_TYPE) + #undef WEBSOCKETS_NETWORK_TYPE + #endif + #define WEBSOCKETS_NETWORK_TYPE NETWORK_RP2040W_WIFI +#else + #error This code is intended to run only on the RP2040W boards ! Please check your Tools->Board setting. +#endif + +#define _WEBSOCKETS_LOGLEVEL_ 2 + +#include + +#include + +WebSocketsClient webSocket; + +int status = WL_IDLE_STATUS; + +#define USE_SSL false + +#if USE_SSL + // Deprecated echo.websocket.org to be replaced + #define WS_SERVER "wss://echo.websocket.org" + #define WS_PORT 443 +#else + // To run a local WebSocket Server + #define WS_SERVER "192.168.2.30" + #define WS_PORT 8080 +#endif + +///////please enter your sensitive data in the Secret tab/arduino_secrets.h + +char ssid[] = "your_ssid"; // your network SSID (name) +char pass[] = "12345678"; // your network password (use for WPA, or use as key for WEP), length must be 8+ + +bool alreadyConnected = false; + +void webSocketEvent(const WStype_t& type, uint8_t * payload, const size_t& length) +{ + switch (type) + { + case WStype_DISCONNECTED: + if (alreadyConnected) + { + Serial.println("[WSc] Disconnected!"); + alreadyConnected = false; + } + + break; + + case WStype_CONNECTED: + { + alreadyConnected = true; + + Serial.print("[WSc] Connected to url: "); + Serial.println((char *) payload); + + // send message to server when Connected + webSocket.sendTXT("Connected"); + } + + break; + + case WStype_TEXT: + Serial.print("[WSc] get text: "); + Serial.println((char *) payload); + + // send message to server + webSocket.sendTXT("message here"); + + break; + + case WStype_BIN: + Serial.print("[WSc] get binary length: "); + Serial.println(length); + + // KH, To check + // hexdump(payload, length); + + // send data to server + webSocket.sendBIN(payload, length); + + break; + + case WStype_PING: + // pong will be send automatically + Serial.println("[WSc] get ping"); + + break; + + case WStype_PONG: + // answer to a ping we send + Serial.println("[WSc] get pong"); + + break; + + default: + break; + } +} + +void printWifiStatus() +{ + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("WebSockets Client IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} + +void setup() +{ + //Initialize serial and wait for port to open: + Serial.begin(115200); + while (!Serial); + + Serial.print("\nStart WebSocketClient_RP2040W on "); Serial.println(BOARD_NAME); + Serial.println(WEBSOCKETS_GENERIC_VERSION); + + /////////////////////////////////// + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) + { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + Serial.print(F("Connecting to SSID: ")); + Serial.println(ssid); + + status = WiFi.begin(ssid, pass); + + delay(1000); + + // attempt to connect to WiFi network + while ( status != WL_CONNECTED) + { + delay(500); + + // Connect to WPA/WPA2 network + status = WiFi.status(); + } + + printWifiStatus(); + + /////////////////////////////////// + + // server address, port and URL + Serial.print("WebSockets Server : "); + Serial.println(WS_SERVER); + + // server address, port and URL +#if USE_SSL + webSocket.beginSSL(WS_SERVER, WS_PORT); +#else + webSocket.begin(WS_SERVER, WS_PORT, "/"); +#endif + + // event handler + webSocket.onEvent(webSocketEvent); + + // server address, port and URL + Serial.print("Connected to WebSockets Server @ "); + Serial.println(WS_SERVER); +} + +void loop() +{ + webSocket.loop(); +} diff --git a/examples/RP2040W/WebSocketClient_Sticky_SocketIO_RP2040W/WebSocketClient_Sticky_SocketIO_RP2040W.ino b/examples/RP2040W/WebSocketClient_Sticky_SocketIO_RP2040W/WebSocketClient_Sticky_SocketIO_RP2040W.ino new file mode 100644 index 00000000..4cc89802 --- /dev/null +++ b/examples/RP2040W/WebSocketClient_Sticky_SocketIO_RP2040W/WebSocketClient_Sticky_SocketIO_RP2040W.ino @@ -0,0 +1,235 @@ +/**************************************************************************************************************************** + WebSocketClient_Sticky_SocketIO_RP2040W.ino + For RP2040W boards using CYC43439 WiFi + + Blynk_WiFiNINA_WM is a library for the Mega, Teensy, SAM DUE, nRF52, STM32 and SAMD boards + (https://github.com/khoih-prog/Blynk_WiFiNINA_WM) to enable easy configuration/reconfiguration and + autoconnect/autoreconnect of WiFiNINA/Blynk + + Based on and modified from WebSockets libarary https://github.com/Links2004/arduinoWebSockets + to support other boards such as SAMD21, SAMD51, Adafruit's nRF52 boards, etc. + + Built by Khoi Hoang https://github.com/khoih-prog/WebSockets_Generic + Licensed under MIT license + + Created on: 24.05.2015 + Author: Markus Sattler + *****************************************************************************************************************************/ + +#if ( defined(ARDUINO_RASPBERRY_PI_PICO_W) ) + #if defined(WEBSOCKETS_NETWORK_TYPE) + #undef WEBSOCKETS_NETWORK_TYPE + #endif + #define WEBSOCKETS_NETWORK_TYPE NETWORK_RP2040W_WIFI +#else + #error This code is intended to run only on the RP2040W boards ! Please check your Tools->Board setting. +#endif + +#define _WEBSOCKETS_LOGLEVEL_ 2 + +#include + +#include + +#include +#include + +SocketIOclient socketIO; + +int status = WL_IDLE_STATUS; + +// Select the IP address according to your local network +IPAddress clientIP(192, 168, 2, 225); + +// Select the IP address according to your local network +IPAddress serverIP(192, 168, 2, 30); +uint16_t serverPort = 8080; + +///////please enter your sensitive data in the Secret tab/arduino_secrets.h + +char ssid[] = "your_ssid"; // your network SSID (name) +char pass[] = "12345678"; // your network password (use for WPA, or use as key for WEP), length must be 8+ + +void socketIOEvent(const socketIOmessageType_t& type, uint8_t * payload, const size_t& length) +{ + switch (type) + { + case sIOtype_DISCONNECT: + Serial.println("[IOc] Disconnected"); + + break; + + case sIOtype_CONNECT: + Serial.print("[IOc] Connected to url: "); + Serial.println((char*) payload); + + // join default namespace (no auto join in Socket.IO V3) + socketIO.send(sIOtype_CONNECT, "/"); + + break; + + case sIOtype_EVENT: + Serial.print("[IOc] Get event: "); + Serial.println((char*) payload); + + break; + + case sIOtype_ACK: + Serial.print("[IOc] Get ack: "); + Serial.println(length); + + //hexdump(payload, length); + + break; + + case sIOtype_ERROR: + Serial.print("[IOc] Get error: "); + Serial.println(length); + + //hexdump(payload, length); + + break; + + case sIOtype_BINARY_EVENT: + Serial.print("[IOc] Get binary: "); + Serial.println(length); + + //hexdump(payload, length); + + break; + + case sIOtype_BINARY_ACK: + Serial.print("[IOc] Get binary ack: "); + Serial.println(length); + + //hexdump(payload, length); + + break; + + case sIOtype_PING: + Serial.println("[IOc] Get PING"); + + break; + + case sIOtype_PONG: + Serial.println("[IOc] Get PONG"); + + break; + + default: + break; + } +} + +void printWifiStatus() +{ + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("WebSockets Client IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} + +void setup() +{ + //Initialize serial and wait for port to open: + Serial.begin(115200); + while (!Serial); + + Serial.print("\nStart WebSocketClient_Sticky_SocketIO_RP2040W on "); Serial.println(BOARD_NAME); + Serial.println(WEBSOCKETS_GENERIC_VERSION); + + /////////////////////////////////// + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) + { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + Serial.print(F("Connecting to SSID: ")); + Serial.println(ssid); + + status = WiFi.begin(ssid, pass); + + delay(1000); + + // attempt to connect to WiFi network + while ( status != WL_CONNECTED) + { + delay(500); + + // Connect to WPA/WPA2 network + status = WiFi.status(); + } + + printWifiStatus(); + + /////////////////////////////////// + + // server address, port and URL + Serial.print("Connecting to WebSockets Server @ IP address: "); + Serial.print(serverIP); + Serial.print(", port: "); + Serial.println(serverPort); + + // setReconnectInterval to 10s, new from v2.5.1 to avoid flooding server. Default is 0.5s + socketIO.setReconnectInterval(10000); + + socketIO.setExtraHeaders("Authorization: 1234567890"); + + // server address, port and URL + // void begin(IPAddress host, uint16_t port, String url = "/socket.io/?EIO=4", String protocol = "arduino"); + // To use default EIO=4 from v2.5.1 + socketIO.begin(serverIP, serverPort); + + // event handler + socketIO.onEvent(socketIOEvent); +} + +unsigned long messageTimestamp = 0; + +void loop() +{ + socketIO.loop(); + + uint64_t now = millis(); + + if (now - messageTimestamp > 30000) + { + messageTimestamp = now; + + // creat JSON message for Socket.IO (event) + DynamicJsonDocument doc(1024); + JsonArray array = doc.to(); + + // add evnet name + // Hint: socket.on('event_name', .... + array.add("event_name"); + + // add payload (parameters) for the event + JsonObject param1 = array.createNestedObject(); + param1["now"] = (uint32_t) now; + + // JSON to String (serializion) + String output; + serializeJson(doc, output); + + // Send event + socketIO.sendEVENT(output); + + // Print JSON for debugging + Serial.println(output); + } +}