Skip to content

Commit d6d4c51

Browse files
authored
Support Arduino UNO WIFI 4 (#894)
feat: Arduino UNO R4 WiFi support
1 parent e364e66 commit d6d4c51

File tree

6 files changed

+135
-8
lines changed

6 files changed

+135
-8
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ a WebSocket Server and Client for Arduino based on RFC6455.
3232
- ATmega328 with enc28j60 (ATmega branch)
3333
- ATmega2560 with Ethernet Shield (ATmega branch)
3434
- ATmega2560 with enc28j60 (ATmega branch)
35+
- Arduino UNO [R4 WiFi](https://github.com/arduino/ArduinoCore-renesas)
3536

3637
###### Note: ######
3738

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#include <Arduino.h>
2+
#include <stdarg.h>
3+
#include <stdio.h>
4+
5+
#include "WiFiS3.h"
6+
#include <WebSocketsClient.h>
7+
8+
#define WIFI_SSID ""
9+
#define WIFI_PASS ""
10+
11+
WebSocketsClient webSocket;
12+
13+
void webSocketEvent(WStype_t type, uint8_t *payload, size_t length) {
14+
15+
switch (type) {
16+
case WStype_DISCONNECTED:
17+
Serial.println("[WSc] Disconnected!");
18+
break;
19+
case WStype_CONNECTED:
20+
Serial.println("[WSc] Connected!");
21+
22+
// send message to server when Connected
23+
webSocket.sendTXT("Connected");
24+
break;
25+
case WStype_TEXT:
26+
Serial.print("[WSc] get text:");
27+
Serial.println((char *)payload);
28+
29+
// send message to server
30+
// webSocket.sendTXT("message here");
31+
break;
32+
case WStype_BIN:
33+
// send data to server
34+
// webSocket.sendBIN(payload, length);
35+
break;
36+
case WStype_ERROR:
37+
case WStype_FRAGMENT_TEXT_START:
38+
case WStype_FRAGMENT_BIN_START:
39+
case WStype_FRAGMENT:
40+
case WStype_FRAGMENT_FIN:
41+
break;
42+
}
43+
}
44+
45+
void setup() {
46+
Serial.begin(115200);
47+
48+
while (!Serial) {
49+
; // wait for serial port to connect. Needed for native USB port only
50+
}
51+
52+
Serial.println();
53+
Serial.println();
54+
Serial.println();
55+
56+
for (uint8_t t = 4; t > 0; t--) {
57+
Serial.println("[SETUP] BOOT WAIT ...");
58+
Serial.flush();
59+
delay(1000);
60+
}
61+
62+
// check for the WiFi module:
63+
if (WiFi.status() == WL_NO_MODULE) {
64+
Serial.println("Communication with WiFi module failed!");
65+
// don't continue
66+
while (true)
67+
;
68+
}
69+
70+
String fv = WiFi.firmwareVersion();
71+
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
72+
Serial.println("Please upgrade the firmware");
73+
}
74+
75+
Serial.println("[Wifi]: Connecting");
76+
77+
int status = WL_IDLE_STATUS;
78+
79+
// attempt to connect to WiFi network:
80+
while (status != WL_CONNECTED) {
81+
Serial.print("[Wifi]: Attempting to connect to SSID: ");
82+
Serial.println(WIFI_SSID);
83+
84+
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
85+
status = WiFi.begin(WIFI_SSID, WIFI_PASS);
86+
87+
delay(1000);
88+
}
89+
90+
Serial.println("Connected!");
91+
92+
// print your board's IP address:
93+
IPAddress ip = WiFi.localIP();
94+
Serial.print("IP Address: ");
95+
Serial.println(ip);
96+
97+
// server address, port and URL
98+
webSocket.begin("192.168.0.123", 8011);
99+
100+
// event handler
101+
webSocket.onEvent(webSocketEvent);
102+
103+
// try ever 5000 again if connection has failed
104+
webSocket.setReconnectInterval(5000);
105+
}
106+
107+
void loop() {
108+
webSocket.loop();
109+
}

Diff for: library.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
"keywords": "wifi, http, web, server, client, websocket",
1717
"license": "LGPL-2.1",
1818
"name": "WebSockets",
19-
"platforms": "atmelavr, espressif8266, espressif32, raspberrypi",
19+
"platforms": "atmelavr, espressif8266, espressif32, raspberrypi, renesas_uno",
2020
"repository": {
2121
"type": "git",
2222
"url": "https://github.com/Links2004/arduinoWebSockets.git"
2323
},
24-
"version": "2.4.2"
25-
}
24+
"version": "2.5.1"
25+
}

Diff for: library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=WebSockets
2-
version=2.4.2
2+
version=2.5.1
33
author=Markus Sattler
44
maintainer=Markus Sattler
55
sentence=WebSockets for Arduino (Server + Client)

Diff for: src/WebSockets.h

+17
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@
9393
#define WEBSOCKETS_YIELD() yield()
9494
#define WEBSOCKETS_YIELD_MORE() delay(1)
9595

96+
#elif defined(ARDUINO_UNOWIFIR4)
97+
98+
#define WEBSOCKETS_MAX_DATA_SIZE (15 * 1024)
99+
#define WEBSOCKETS_YIELD() yield()
100+
#define WEBSOCKETS_YIELD_MORE() delay(1)
101+
96102
#else
97103

98104
// atmega328p has only 2KB ram!
@@ -114,6 +120,7 @@
114120
#define NETWORK_ESP32 (4)
115121
#define NETWORK_ESP32_ETH (5)
116122
#define NETWORK_RP2040 (6)
123+
#define NETWORK_UNOWIFIR4 (7)
117124

118125
// max size of the WS Message Header
119126
#define WEBSOCKETS_MAX_HEADER_SIZE (14)
@@ -132,6 +139,9 @@
132139
#elif defined(ARDUINO_ARCH_RP2040)
133140
#define WEBSOCKETS_NETWORK_TYPE NETWORK_RP2040
134141

142+
#elif defined(ARDUINO_UNOWIFIR4)
143+
#define WEBSOCKETS_NETWORK_TYPE NETWORK_UNOWIFIR4
144+
135145
#else
136146
#define WEBSOCKETS_NETWORK_TYPE NETWORK_W5100
137147

@@ -224,6 +234,13 @@
224234
#define WEBSOCKETS_NETWORK_SSL_CLASS WiFiClientSecure
225235
#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer
226236

237+
#elif(WEBSOCKETS_NETWORK_TYPE == NETWORK_UNOWIFIR4)
238+
239+
#include <WiFiS3.h>
240+
241+
#define WEBSOCKETS_NETWORK_CLASS WiFiClient
242+
#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer
243+
227244
#else
228245
#error "no network type selected!"
229246
#endif

Diff for: src/WebSocketsVersion.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
#ifndef WEBSOCKETSVERSION_H_
2626
#define WEBSOCKETSVERSION_H_
2727

28-
#define WEBSOCKETS_VERSION "2.4.2"
28+
#define WEBSOCKETS_VERSION "2.5.1"
2929

3030
#define WEBSOCKETS_VERSION_MAJOR 2
31-
#define WEBSOCKETS_VERSION_MINOR 4
32-
#define WEBSOCKETS_VERSION_PATCH 2
31+
#define WEBSOCKETS_VERSION_MINOR 5
32+
#define WEBSOCKETS_VERSION_PATCH 1
3333

34-
#define WEBSOCKETS_VERSION_INT 2004002
34+
#define WEBSOCKETS_VERSION_INT 2005001
3535

3636
#endif /* WEBSOCKETSVERSION_H_ */

0 commit comments

Comments
 (0)