Skip to content

Commit 899cfbd

Browse files
authored
feat: Support Nano 33 IoT, MKR WIFI 1010, XIAO, Wio Terminal (#901)
1 parent dcfb0df commit 899cfbd

14 files changed

+286
-20
lines changed

.github/workflows/compile-arduino_wifinina-examples.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
name: Compile Arduino WiFiNINA Examples
22

33
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
4-
on: [push, pull_request]
4+
on:
5+
push:
6+
paths:
7+
- ".github/workflows/compile-arduino_wifinina-examples.yaml"
8+
- "examples/arduino_wifinina/**"
9+
- "src/**"
10+
pull_request:
11+
paths:
12+
- ".github/workflows/compile-arduino_wifinina-examples.yaml"
13+
- "examples/arduino_wifinina/**"
14+
- "src/**"
15+
schedule:
16+
# Run every Tuesday at 8 AM UTC to catch breakage caused by changes to external resources (libraries, platforms).
17+
- cron: "0 8 * * TUE"
18+
workflow_dispatch:
19+
repository_dispatch:
520

621
jobs:
722
build:
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Compile SeedStudio Examples
2+
3+
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
4+
on:
5+
push:
6+
paths:
7+
- ".github/workflows/compile-seeed-studio-examples.yaml"
8+
- "examples/seeed-studio/**"
9+
- "src/**"
10+
pull_request:
11+
paths:
12+
- ".github/workflows/compile-seeed-studio-examples.yaml"
13+
- "examples/seeed-studio/**"
14+
- "src/**"
15+
schedule:
16+
# Run every Tuesday at 8 AM UTC to catch breakage caused by changes to external resources (libraries, platforms).
17+
- cron: "0 8 * * TUE"
18+
workflow_dispatch:
19+
repository_dispatch:
20+
21+
jobs:
22+
build:
23+
name: ${{ matrix.board.fqbn }}
24+
runs-on: ubuntu-latest
25+
26+
env:
27+
SKETCHES_REPORTS_PATH: sketches-reports
28+
29+
strategy:
30+
fail-fast: false
31+
32+
matrix:
33+
board:
34+
- fqbn: Seeeduino:samd:seeed_XIAO_m0:usbstack=arduino,debug=off
35+
platforms: |
36+
- name: Seeeduino:samd
37+
source-url: https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json
38+
libraries: |
39+
- name: Seeed Arduino rpcWiFi
40+
- name: Seeed Arduino rpcUnified
41+
- name: Seeed_Arduino_mbedtls
42+
- name: Seeed Arduino FS
43+
- name: Seeed Arduino SFUD
44+
artifact-name-suffix: seeeduino-xia0
45+
- fqbn: Seeeduino:samd:seeed_wio_terminal
46+
platforms: |
47+
- name: Seeeduino:samd
48+
source-url: https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json
49+
libraries: |
50+
- name: Seeed Arduino rpcWiFi
51+
- name: Seeed Arduino rpcUnified
52+
- name: Seeed_Arduino_mbedtls
53+
- name: Seeed Arduino FS
54+
- name: Seeed Arduino SFUD
55+
artifact-name-suffix: seeeduino-wio_terminal
56+
57+
steps:
58+
- name: Checkout repository
59+
uses: actions/checkout@v4
60+
61+
- name: Compile examples
62+
uses: arduino/compile-sketches@v1
63+
with:
64+
github-token: ${{ secrets.GITHUB_TOKEN }}
65+
fqbn: ${{ matrix.board.fqbn }}
66+
platforms: ${{ matrix.board.platforms }}
67+
libraries: |
68+
# Install the library from the local path.
69+
- source-path: ./
70+
${{ matrix.board.libraries }}
71+
sketch-paths: |
72+
- examples/seeed-studio/xio-wio-terminal/WebSocketClient
73+
enable-deltas-report: true
74+
sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }}
75+
76+
- name: Save sketches report as workflow artifact
77+
uses: actions/upload-artifact@v4
78+
with:
79+
if-no-files-found: error
80+
path: ${{ env.SKETCHES_REPORTS_PATH }}
81+
name: sketches-report-${{ matrix.board.artifact-name-suffix }}

.github/workflows/compile-unor4wifi-examples.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
name: Compile Arduino UNO R4 WiFi Examples
22

33
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
4-
on: [push, pull_request]
4+
on:
5+
push:
6+
paths:
7+
- ".github/workflows/compile-unor4wifi-examples.yaml"
8+
- "examples/arduino_renesas/**"
9+
- "src/**"
10+
pull_request:
11+
paths:
12+
- ".github/workflows/compile-unor4wifi-examples.yaml"
13+
- "examples/arduino_renesas/**"
14+
- "src/**"
15+
schedule:
16+
# Run every Tuesday at 8 AM UTC to catch breakage caused by changes to external resources (libraries, platforms).
17+
- cron: "0 8 * * TUE"
18+
workflow_dispatch:
19+
repository_dispatch:
520

621
jobs:
722
build:

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ 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
36+
- Arduino Nano 33 IoT, MKR WIFI 1010 (requires [WiFiNINA](https://github.com/arduino-libraries/WiFiNINA/) library)
37+
- Seeeduino XIAO, Seeeduino Wio Terminal (requires [rpcWiFi](https://github.com/Seeed-Studio/Seeed_Arduino_rpcWiFi) library)
3738

3839
###### Note: ######
3940

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* WebSocketClient.ino
3+
*
4+
* Created on: 10.08.2024
5+
*
6+
*/
7+
8+
#include <Arduino.h>
9+
#include <rpcWiFi.h>
10+
#include <WiFiMulti.h>
11+
#include <WebSocketsClient.h>
12+
13+
WebSocketsClient webSocket;
14+
WiFiMulti wifiMulti;
15+
16+
#define USE_SERIAL Serial
17+
18+
void hexdump(const void *mem, uint32_t len, uint8_t cols = 16) {
19+
const uint8_t* src = (const uint8_t*) mem;
20+
USE_SERIAL.printf("\n[HEXDUMP] Address: 0x%08X len: 0x%X (%d)", (ptrdiff_t)src, len, len);
21+
for(uint32_t i = 0; i < len; i++) {
22+
if(i % cols == 0) {
23+
USE_SERIAL.printf("\n[0x%08X] 0x%08X: ", (ptrdiff_t)src, i);
24+
}
25+
USE_SERIAL.printf("%02X ", *src);
26+
src++;
27+
}
28+
USE_SERIAL.printf("\n");
29+
}
30+
31+
void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
32+
33+
switch(type) {
34+
case WStype_DISCONNECTED:
35+
USE_SERIAL.printf("[WSc] Disconnected!\n");
36+
break;
37+
case WStype_CONNECTED:
38+
USE_SERIAL.printf("[WSc] Connected to url: %s\n", payload);
39+
40+
// send message to server when Connected
41+
webSocket.sendTXT("Connected");
42+
break;
43+
case WStype_TEXT:
44+
USE_SERIAL.printf("[WSc] get text: %s\n", payload);
45+
46+
// send message to server
47+
// webSocket.sendTXT("message here");
48+
break;
49+
case WStype_BIN:
50+
USE_SERIAL.printf("[WSc] get binary length: %u\n", length);
51+
hexdump(payload, length);
52+
53+
// send data to server
54+
// webSocket.sendBIN(payload, length);
55+
break;
56+
case WStype_ERROR:
57+
case WStype_FRAGMENT_TEXT_START:
58+
case WStype_FRAGMENT_BIN_START:
59+
case WStype_FRAGMENT:
60+
case WStype_PONG:
61+
case WStype_PING:
62+
case WStype_FRAGMENT_FIN:
63+
break;
64+
}
65+
66+
}
67+
68+
void setup() {
69+
// USE_SERIAL.begin(921600);
70+
USE_SERIAL.begin(115200);
71+
72+
USE_SERIAL.println();
73+
USE_SERIAL.println();
74+
USE_SERIAL.println();
75+
76+
for(uint8_t t = 4; t > 0; t--) {
77+
USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t);
78+
USE_SERIAL.flush();
79+
delay(1000);
80+
}
81+
82+
wifiMulti.addAP("SSID", "passpasspass");
83+
84+
//WiFi.disconnect();
85+
while(wifiMulti.run() != WL_CONNECTED) {
86+
delay(100);
87+
}
88+
89+
// server address, port and URL
90+
webSocket.begin("192.168.0.123", 81, "/");
91+
92+
// event handler
93+
webSocket.onEvent(webSocketEvent);
94+
95+
// use HTTP Basic Authorization this is optional remove if not needed
96+
webSocket.setAuthorization("user", "Password");
97+
98+
// try ever 5000 again if connection has failed
99+
webSocket.setReconnectInterval(5000);
100+
101+
}
102+
103+
void loop() {
104+
webSocket.loop();
105+
}

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"keywords": "wifi, http, web, server, client, websocket",
1717
"license": "LGPL-2.1",
1818
"name": "WebSockets",
19-
"platforms": "atmelavr, espressif8266, espressif32, raspberrypi, renesas_uno",
19+
"platforms": "*",
2020
"repository": {
2121
"type": "git",
2222
"url": "https://github.com/Links2004/arduinoWebSockets.git"

src/SocketIOclient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,4 @@ void SocketIOclient::handleCbEvent(WStype_t type, uint8_t * payload, size_t leng
261261
case WStype_PONG:
262262
break;
263263
}
264-
}
264+
}

src/SocketIOclient.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ class SocketIOclient : protected WebSocketsClient {
5555
void beginSSL(String host, uint16_t port, String url = "/socket.io/?EIO=3", String protocol = "arduino", uint32_t pingInterval = 60 * 1000, uint32_t pongTimeout = 90 * 1000, uint8_t disconnectTimeoutCount = 5);
5656
#ifndef SSL_AXTLS
5757
void beginSSLWithCA(const char * host, uint16_t port, const char * url = "/socket.io/?EIO=3", const char * CA_cert = NULL, const char * protocol = "arduino", uint32_t pingInterval = 60 * 1000, uint32_t pongTimeout = 90 * 1000, uint8_t disconnectTimeoutCount = 5);
58-
void beginSSLWithCA(const char * host, uint16_t port, const char * url = "/socket.io/?EIO=3", BearSSL::X509List * CA_cert = NULL, const char * protocol = "arduino", uint32_t pingInterval = 60 * 1000, uint32_t pongTimeout = 90 * 1000, uint8_t disconnectTimeoutCount = 5);
5958
void setSSLClientCertKey(const char * clientCert = NULL, const char * clientPrivateKey = NULL);
59+
#if defined(SSL_BARESSL)
60+
void beginSSLWithCA(const char * host, uint16_t port, const char * url = "/socket.io/?EIO=3", BearSSL::X509List * CA_cert = NULL, const char * protocol = "arduino", uint32_t pingInterval = 60 * 1000, uint32_t pongTimeout = 90 * 1000, uint8_t disconnectTimeoutCount = 5);
6061
void setSSLClientCertKey(BearSSL::X509List * clientCert = NULL, BearSSL::PrivateKey * clientPrivateKey = NULL);
62+
#endif
6163
#endif
6264
#endif
6365
bool isConnected(void);

src/WebSockets.h

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@
105105
#define WEBSOCKETS_YIELD() yield()
106106
#define WEBSOCKETS_YIELD_MORE() delay(1)
107107

108+
#elif defined(WIO_TERMINAL) || defined(SEEED_XIAO_M0)
109+
110+
#define WEBSOCKETS_MAX_DATA_SIZE (15 * 1024)
111+
#define WEBSOCKETS_YIELD() yield()
112+
#define WEBSOCKETS_YIELD_MORE() delay(1)
113+
108114
#else
109115

110116
// atmega328p has only 2KB ram!
@@ -128,7 +134,7 @@
128134
#define NETWORK_RP2040 (6)
129135
#define NETWORK_UNOWIFIR4 (7)
130136
#define NETWORK_WIFI_NINA (8)
131-
137+
#define NETWORK_SAMD_SEED (9)
132138

133139
// max size of the WS Message Header
134140
#define WEBSOCKETS_MAX_HEADER_SIZE (14)
@@ -153,6 +159,9 @@
153159
#elif defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT)
154160
#define WEBSOCKETS_NETWORK_TYPE NETWORK_WIFI_NINA
155161

162+
#elif defined(WIO_TERMINAL) || defined(SEEED_XIAO_M0)
163+
#define WEBSOCKETS_NETWORK_TYPE NETWORK_SAMD_SEED
164+
156165
#else
157166
#define WEBSOCKETS_NETWORK_TYPE NETWORK_W5100
158167

@@ -248,10 +257,6 @@
248257
#elif(WEBSOCKETS_NETWORK_TYPE == NETWORK_UNOWIFIR4)
249258

250259
#include <WiFiS3.h>
251-
252-
#define WEBSOCKETS_NETWORK_CLASS WiFiClient
253-
#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer
254-
255260
#define WEBSOCKETS_NETWORK_CLASS WiFiClient
256261
#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer
257262

@@ -264,6 +269,23 @@
264269

265270
#define WEBSOCKETS_NETWORK_CLASS WiFiClient
266271
#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer
272+
#define WEBSOCKETS_NETWORK_SSL_CLASS WiFiSSLClient
273+
274+
#elif(WEBSOCKETS_NETWORK_TYPE == NETWORK_SAMD_SEED)
275+
#if __has_include(<rpcWiFi.h>) && __has_include(<rpcWiFiClientSecure.h>)
276+
#include <rpcWiFi.h>
277+
#include <rpcWiFiClientSecure.h>
278+
#else
279+
#error "Please install rpcWiFi library!"
280+
#endif
281+
282+
#define WEBSOCKETS_NETWORK_CLASS WiFiClient
283+
#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer
284+
#define WEBSOCKETS_NETWORK_SSL_CLASS WiFiClientSecure
285+
286+
#define WEBSOCKETS_NETWORK_CLASS WiFiClient
287+
#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer
288+
267289
#else
268290
#error "no network type selected!"
269291
#endif

0 commit comments

Comments
 (0)