Skip to content

Commit dcfb0df

Browse files
authored
feat: Support Arduino Nano 33 IoT, MKR WIFI 1010 (#898)
1 parent dc6fd04 commit dcfb0df

11 files changed

+257
-9
lines changed

.github/workflows/arduino-lint.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Arduino library compliance (Lint)
2+
on: [push, pull_request]
3+
jobs:
4+
lint:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v3
8+
- uses: arduino/arduino-lint-action@v1
9+
with:
10+
library-manager: update
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Compile Arduino WiFiNINA Examples
2+
3+
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
4+
on: [push, pull_request]
5+
6+
jobs:
7+
build:
8+
name: ${{ matrix.board.fqbn }}
9+
runs-on: ubuntu-latest
10+
11+
env:
12+
SKETCHES_REPORTS_PATH: sketches-reports
13+
14+
strategy:
15+
fail-fast: false
16+
17+
matrix:
18+
board:
19+
- fqbn: arduino:samd:mkrwifi1010
20+
platforms: |
21+
- name: arduino:samd
22+
artifact-name-suffix: arduino-samd-mkrwifi1010
23+
libraries: |
24+
- name: WiFiNINA
25+
- fqbn: arduino:samd:nano_33_iot
26+
platforms: |
27+
- name: arduino:samd
28+
artifact-name-suffix: arduino-samd-nano_33_iot
29+
libraries: |
30+
- name: WiFiNINA
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@v4
34+
35+
- name: Compile examples
36+
uses: arduino/compile-sketches@v1
37+
with:
38+
fqbn: ${{ matrix.board.fqbn }}
39+
platforms: ${{ matrix.board.platforms }}
40+
libraries: |
41+
# Install the library from the local path.
42+
- source-path: ./
43+
${{ matrix.board.libraries }}
44+
sketch-paths: |
45+
- examples/arduino_wifinina/arduino_wifinina.ino
46+
enable-deltas-report: true
47+
sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }}
48+
49+
- name: Save sketches report as workflow artifact
50+
uses: actions/upload-artifact@v4
51+
with:
52+
if-no-files-found: error
53+
path: ${{ env.SKETCHES_REPORTS_PATH }}
54+
name: sketches-report-${{ matrix.board.artifact-name-suffix }}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Compile Arduino UNO R4 WiFi Examples
2+
3+
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
4+
on: [push, pull_request]
5+
6+
jobs:
7+
build:
8+
name: ${{ matrix.board.fqbn }}
9+
runs-on: ubuntu-latest
10+
11+
env:
12+
SKETCHES_REPORTS_PATH: sketches-reports
13+
14+
strategy:
15+
fail-fast: false
16+
17+
matrix:
18+
board:
19+
- fqbn: arduino:renesas_uno:unor4wifi
20+
platforms: |
21+
- name: arduino:renesas_uno
22+
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v4
26+
27+
- name: Compile examples
28+
uses: arduino/compile-sketches@v1
29+
with:
30+
fqbn: ${{ matrix.board.fqbn }}
31+
platforms: ${{ matrix.board.platforms }}
32+
libraries: |
33+
# Install the library from the local path.
34+
- source-path: ./
35+
sketch-paths: |
36+
- examples/arduino_renesas/arduino_uno_r4_wifi
37+
enable-deltas-report: true
38+
sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }}
39+
40+
- name: Save sketches report as workflow artifact
41+
uses: actions/upload-artifact@v4
42+
with:
43+
if-no-files-found: error
44+
path: ${{ env.SKETCHES_REPORTS_PATH }}
45+
name: sketches-report-${{ matrix.board.artifact-name-suffix }}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ a WebSocket Server and Client for Arduino based on RFC6455.
3333
- ATmega2560 with Ethernet Shield (ATmega branch)
3434
- ATmega2560 with enc28j60 (ATmega branch)
3535
- Arduino UNO [R4 WiFi](https://github.com/arduino/ArduinoCore-renesas)
36+
- Arduino Nano 33 IoT, MKR WIFI 1010
3637

3738
###### Note: ######
3839

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#include <Arduino.h>
2+
#include <SPI.h>
3+
#include <WiFiNINA.h>
4+
#include <WebSocketsClient.h>
5+
6+
#define WIFI_SSID ""
7+
#define WIFI_PASS ""
8+
9+
int status = WL_IDLE_STATUS;
10+
WiFiClient client;
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_PING:
41+
case WStype_PONG:
42+
case WStype_FRAGMENT_FIN:
43+
break;
44+
}
45+
}
46+
47+
void setup() {
48+
Serial.begin(115200);
49+
50+
while (!Serial) {
51+
; // wait for serial port to connect. Needed for native USB port only
52+
}
53+
54+
Serial.println();
55+
Serial.println();
56+
Serial.println();
57+
58+
// check for the WiFi module:
59+
if (WiFi.status() == WL_NO_MODULE) {
60+
Serial.println("Communication with WiFi module failed!");
61+
// don't continue
62+
while (true);
63+
}
64+
65+
String fv = WiFi.firmwareVersion();
66+
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
67+
Serial.println("Please upgrade the firmware");
68+
}
69+
70+
// attempt to connect to WiFi network:
71+
while (status != WL_CONNECTED) {
72+
Serial.print("Attempting to connect to SSID: ");
73+
Serial.println(WIFI_SSID);
74+
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
75+
status = WiFi.begin(WIFI_SSID, WIFI_PASS);
76+
77+
// wait 10 seconds for connection:
78+
delay(10000);
79+
}
80+
81+
Serial.println("Connected to WiFi");
82+
83+
// print your board's IP address:
84+
IPAddress ip = WiFi.localIP();
85+
Serial.print("IP Address: ");
86+
Serial.println(ip);
87+
88+
// server address, port and URL
89+
webSocket.begin("192.168.0.123", 8011);
90+
91+
// event handler
92+
webSocket.onEvent(webSocketEvent);
93+
94+
// try ever 5000 again if connection has failed
95+
webSocket.setReconnectInterval(5000);
96+
}
97+
98+
void loop() {
99+
webSocket.loop();
100+
}

library.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
"type": "git",
2222
"url": "https://github.com/Links2004/arduinoWebSockets.git"
2323
},
24-
"version": "2.5.2"
25-
}
24+
"version": "2.5.3"
25+
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=WebSockets
2-
version=2.5.2
2+
version=2.5.3
33
author=Markus Sattler
44
maintainer=Markus Sattler
55
sentence=WebSockets for Arduino (Server + Client)

src/WebSockets.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@
9999
#define WEBSOCKETS_YIELD() yield()
100100
#define WEBSOCKETS_YIELD_MORE() delay(1)
101101

102+
#elif defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT)
103+
104+
#define WEBSOCKETS_MAX_DATA_SIZE (15 * 1024)
105+
#define WEBSOCKETS_YIELD() yield()
106+
#define WEBSOCKETS_YIELD_MORE() delay(1)
107+
102108
#else
103109

104110
// atmega328p has only 2KB ram!
@@ -121,6 +127,8 @@
121127
#define NETWORK_ESP32_ETH (5)
122128
#define NETWORK_RP2040 (6)
123129
#define NETWORK_UNOWIFIR4 (7)
130+
#define NETWORK_WIFI_NINA (8)
131+
124132

125133
// max size of the WS Message Header
126134
#define WEBSOCKETS_MAX_HEADER_SIZE (14)
@@ -142,6 +150,9 @@
142150
#elif defined(ARDUINO_UNOWIFIR4)
143151
#define WEBSOCKETS_NETWORK_TYPE NETWORK_UNOWIFIR4
144152

153+
#elif defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT)
154+
#define WEBSOCKETS_NETWORK_TYPE NETWORK_WIFI_NINA
155+
145156
#else
146157
#define WEBSOCKETS_NETWORK_TYPE NETWORK_W5100
147158

@@ -241,6 +252,18 @@
241252
#define WEBSOCKETS_NETWORK_CLASS WiFiClient
242253
#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer
243254

255+
#define WEBSOCKETS_NETWORK_CLASS WiFiClient
256+
#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer
257+
258+
#elif(WEBSOCKETS_NETWORK_TYPE == NETWORK_WIFI_NINA)
259+
#if __has_include(<WiFiNINA.h>)
260+
#include <WiFiNINA.h>
261+
#else
262+
#error "Please install WiFiNINA library!"
263+
#endif
264+
265+
#define WEBSOCKETS_NETWORK_CLASS WiFiClient
266+
#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer
244267
#else
245268
#error "no network type selected!"
246269
#endif

src/WebSocketsClient.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,11 @@ void WebSocketsClient::clientDisconnect(WSclient_t * client) {
534534
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
535535
client->status = WSC_NOT_CONNECTED;
536536
#else
537-
delete client->tcp;
537+
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_WIFI_NINA)
538+
// does not support delete (no destructor)
539+
#else
540+
delete client->tcp;
541+
#endif
538542
#endif
539543
client->tcp = NULL;
540544
}

src/WebSocketsServer.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ WebSocketsServerCore::~WebSocketsServerCore() {
6565
}
6666

6767
WebSocketsServer::~WebSocketsServer() {
68-
delete _server;
68+
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_WIFI_NINA)
69+
// does not support delete (no destructor)
70+
#else
71+
delete _server;
72+
#endif
6973
}
7074

7175
/**
@@ -539,6 +543,8 @@ void WebSocketsServerCore::dropNativeClient(WSclient_t * client) {
539543
}
540544
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
541545
client->status = WSC_NOT_CONNECTED;
546+
#elif(WEBSOCKETS_NETWORK_TYPE == NETWORK_WIFI_NINA)
547+
// does not support delete (no destructor)
542548
#else
543549
delete client->tcp;
544550
#endif
@@ -655,7 +661,12 @@ void WebSocketsServer::handleNewClients(void) {
655661
#endif
656662

657663
// store new connection
658-
WEBSOCKETS_NETWORK_CLASS * tcpClient = new WEBSOCKETS_NETWORK_CLASS(_server->accept());
664+
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_WIFI_NINA)
665+
WEBSOCKETS_NETWORK_CLASS * tcpClient = new WEBSOCKETS_NETWORK_CLASS(_server->available());
666+
#else
667+
WEBSOCKETS_NETWORK_CLASS * tcpClient = new WEBSOCKETS_NETWORK_CLASS(_server->accept());
668+
#endif
669+
659670
if(!tcpClient) {
660671
DEBUG_WEBSOCKETS("[WS-Client] creating Network class failed!");
661672
return;

src/WebSocketsVersion.h

Lines changed: 3 additions & 3 deletions
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.5.2"
28+
#define WEBSOCKETS_VERSION "2.5.3"
2929

3030
#define WEBSOCKETS_VERSION_MAJOR 2
3131
#define WEBSOCKETS_VERSION_MINOR 5
32-
#define WEBSOCKETS_VERSION_PATCH 2
32+
#define WEBSOCKETS_VERSION_PATCH 3
3333

34-
#define WEBSOCKETS_VERSION_INT 2005002
34+
#define WEBSOCKETS_VERSION_INT 2005003
3535

3636
#endif /* WEBSOCKETSVERSION_H_ */

0 commit comments

Comments
 (0)