diff --git a/README.md b/README.md index fdc4e4c..b5930eb 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ a WebSocket Server and Client for Arduino based on RFC6455. - ATmega328 with enc28j60 (ATmega branch) - ATmega2560 with Ethernet Shield (ATmega branch) - ATmega2560 with enc28j60 (ATmega branch) + - Arduino UNO [R4 WiFi](https://github.com/arduino/ArduinoCore-renesas) ###### Note: ###### diff --git a/examples/arduino_renesas/arduino_uno_r4_wifi/arduino_uno_r4_wifi.ino b/examples/arduino_renesas/arduino_uno_r4_wifi/arduino_uno_r4_wifi.ino new file mode 100644 index 0000000..2168a62 --- /dev/null +++ b/examples/arduino_renesas/arduino_uno_r4_wifi/arduino_uno_r4_wifi.ino @@ -0,0 +1,109 @@ +#include +#include +#include + +#include "WiFiS3.h" +#include + +#define WIFI_SSID "" +#define WIFI_PASS "" + +WebSocketsClient webSocket; + +void webSocketEvent(WStype_t type, uint8_t *payload, size_t length) { + + switch (type) { + case WStype_DISCONNECTED: + Serial.println("[WSc] Disconnected!"); + break; + case WStype_CONNECTED: + Serial.println("[WSc] Connected!"); + + // 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: + // send data to server + // webSocket.sendBIN(payload, length); + break; + case WStype_ERROR: + case WStype_FRAGMENT_TEXT_START: + case WStype_FRAGMENT_BIN_START: + case WStype_FRAGMENT: + case WStype_FRAGMENT_FIN: + break; + } +} + +void setup() { + Serial.begin(115200); + + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println(); + Serial.println(); + Serial.println(); + + for (uint8_t t = 4; t > 0; t--) { + Serial.println("[SETUP] BOOT WAIT ..."); + Serial.flush(); + delay(1000); + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + Serial.println("[Wifi]: Connecting"); + + int status = WL_IDLE_STATUS; + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("[Wifi]: Attempting to connect to SSID: "); + Serial.println(WIFI_SSID); + + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(WIFI_SSID, WIFI_PASS); + + delay(1000); + } + + Serial.println("Connected!"); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // server address, port and URL + webSocket.begin("192.168.0.123", 8011); + + // event handler + webSocket.onEvent(webSocketEvent); + + // try ever 5000 again if connection has failed + webSocket.setReconnectInterval(5000); +} + +void loop() { + webSocket.loop(); +} \ No newline at end of file diff --git a/library.json b/library.json index 2a5ed65..d51149f 100644 --- a/library.json +++ b/library.json @@ -16,10 +16,10 @@ "keywords": "wifi, http, web, server, client, websocket", "license": "LGPL-2.1", "name": "WebSockets", - "platforms": "atmelavr, espressif8266, espressif32, raspberrypi", + "platforms": "atmelavr, espressif8266, espressif32, raspberrypi, renesas_uno", "repository": { "type": "git", "url": "https://github.com/Links2004/arduinoWebSockets.git" }, - "version": "2.4.2" -} \ No newline at end of file + "version": "2.5.1" +} diff --git a/library.properties b/library.properties index 487596c..462efc5 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=WebSockets -version=2.4.2 +version=2.5.1 author=Markus Sattler maintainer=Markus Sattler sentence=WebSockets for Arduino (Server + Client) diff --git a/src/WebSockets.h b/src/WebSockets.h index db6c0e8..56b4988 100644 --- a/src/WebSockets.h +++ b/src/WebSockets.h @@ -93,6 +93,12 @@ #define WEBSOCKETS_YIELD() yield() #define WEBSOCKETS_YIELD_MORE() delay(1) +#elif defined(ARDUINO_UNOWIFIR4) + +#define WEBSOCKETS_MAX_DATA_SIZE (15 * 1024) +#define WEBSOCKETS_YIELD() yield() +#define WEBSOCKETS_YIELD_MORE() delay(1) + #else // atmega328p has only 2KB ram! @@ -114,6 +120,7 @@ #define NETWORK_ESP32 (4) #define NETWORK_ESP32_ETH (5) #define NETWORK_RP2040 (6) +#define NETWORK_UNOWIFIR4 (7) // max size of the WS Message Header #define WEBSOCKETS_MAX_HEADER_SIZE (14) @@ -132,6 +139,9 @@ #elif defined(ARDUINO_ARCH_RP2040) #define WEBSOCKETS_NETWORK_TYPE NETWORK_RP2040 +#elif defined(ARDUINO_UNOWIFIR4) +#define WEBSOCKETS_NETWORK_TYPE NETWORK_UNOWIFIR4 + #else #define WEBSOCKETS_NETWORK_TYPE NETWORK_W5100 @@ -224,6 +234,13 @@ #define WEBSOCKETS_NETWORK_SSL_CLASS WiFiClientSecure #define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer +#elif(WEBSOCKETS_NETWORK_TYPE == NETWORK_UNOWIFIR4) + +#include + +#define WEBSOCKETS_NETWORK_CLASS WiFiClient +#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer + #else #error "no network type selected!" #endif diff --git a/src/WebSocketsVersion.h b/src/WebSocketsVersion.h index 11fc8b1..9c69078 100644 --- a/src/WebSocketsVersion.h +++ b/src/WebSocketsVersion.h @@ -25,12 +25,12 @@ #ifndef WEBSOCKETSVERSION_H_ #define WEBSOCKETSVERSION_H_ -#define WEBSOCKETS_VERSION "2.4.2" +#define WEBSOCKETS_VERSION "2.5.1" #define WEBSOCKETS_VERSION_MAJOR 2 -#define WEBSOCKETS_VERSION_MINOR 4 -#define WEBSOCKETS_VERSION_PATCH 2 +#define WEBSOCKETS_VERSION_MINOR 5 +#define WEBSOCKETS_VERSION_PATCH 1 -#define WEBSOCKETS_VERSION_INT 2004002 +#define WEBSOCKETS_VERSION_INT 2005001 #endif /* WEBSOCKETSVERSION_H_ */