Skip to content

Commit

Permalink
feat: Support Nano 33 IoT, MKR WIFI 1010, XIAO, Wio Terminal (#901)
Browse files Browse the repository at this point in the history
  • Loading branch information
kakopappa authored Aug 24, 2024
1 parent dcfb0df commit 899cfbd
Show file tree
Hide file tree
Showing 14 changed files with 286 additions and 20 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/compile-arduino_wifinina-examples.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
name: Compile Arduino WiFiNINA Examples

# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
on: [push, pull_request]
on:
push:
paths:
- ".github/workflows/compile-arduino_wifinina-examples.yaml"
- "examples/arduino_wifinina/**"
- "src/**"
pull_request:
paths:
- ".github/workflows/compile-arduino_wifinina-examples.yaml"
- "examples/arduino_wifinina/**"
- "src/**"
schedule:
# Run every Tuesday at 8 AM UTC to catch breakage caused by changes to external resources (libraries, platforms).
- cron: "0 8 * * TUE"
workflow_dispatch:
repository_dispatch:

jobs:
build:
Expand Down
81 changes: 81 additions & 0 deletions .github/workflows/compile-seeed-studio-examples.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Compile SeedStudio Examples

# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
on:
push:
paths:
- ".github/workflows/compile-seeed-studio-examples.yaml"
- "examples/seeed-studio/**"
- "src/**"
pull_request:
paths:
- ".github/workflows/compile-seeed-studio-examples.yaml"
- "examples/seeed-studio/**"
- "src/**"
schedule:
# Run every Tuesday at 8 AM UTC to catch breakage caused by changes to external resources (libraries, platforms).
- cron: "0 8 * * TUE"
workflow_dispatch:
repository_dispatch:

jobs:
build:
name: ${{ matrix.board.fqbn }}
runs-on: ubuntu-latest

env:
SKETCHES_REPORTS_PATH: sketches-reports

strategy:
fail-fast: false

matrix:
board:
- fqbn: Seeeduino:samd:seeed_XIAO_m0:usbstack=arduino,debug=off
platforms: |
- name: Seeeduino:samd
source-url: https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json
libraries: |
- name: Seeed Arduino rpcWiFi
- name: Seeed Arduino rpcUnified
- name: Seeed_Arduino_mbedtls
- name: Seeed Arduino FS
- name: Seeed Arduino SFUD
artifact-name-suffix: seeeduino-xia0
- fqbn: Seeeduino:samd:seeed_wio_terminal
platforms: |
- name: Seeeduino:samd
source-url: https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json
libraries: |
- name: Seeed Arduino rpcWiFi
- name: Seeed Arduino rpcUnified
- name: Seeed_Arduino_mbedtls
- name: Seeed Arduino FS
- name: Seeed Arduino SFUD
artifact-name-suffix: seeeduino-wio_terminal

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Compile examples
uses: arduino/compile-sketches@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
fqbn: ${{ matrix.board.fqbn }}
platforms: ${{ matrix.board.platforms }}
libraries: |
# Install the library from the local path.
- source-path: ./
${{ matrix.board.libraries }}
sketch-paths: |
- examples/seeed-studio/xio-wio-terminal/WebSocketClient
enable-deltas-report: true
sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }}

- name: Save sketches report as workflow artifact
uses: actions/upload-artifact@v4
with:
if-no-files-found: error
path: ${{ env.SKETCHES_REPORTS_PATH }}
name: sketches-report-${{ matrix.board.artifact-name-suffix }}
17 changes: 16 additions & 1 deletion .github/workflows/compile-unor4wifi-examples.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
name: Compile Arduino UNO R4 WiFi Examples

# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
on: [push, pull_request]
on:
push:
paths:
- ".github/workflows/compile-unor4wifi-examples.yaml"
- "examples/arduino_renesas/**"
- "src/**"
pull_request:
paths:
- ".github/workflows/compile-unor4wifi-examples.yaml"
- "examples/arduino_renesas/**"
- "src/**"
schedule:
# Run every Tuesday at 8 AM UTC to catch breakage caused by changes to external resources (libraries, platforms).
- cron: "0 8 * * TUE"
workflow_dispatch:
repository_dispatch:

jobs:
build:
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ a WebSocket Server and Client for Arduino based on RFC6455.
- ATmega2560 with Ethernet Shield (ATmega branch)
- ATmega2560 with enc28j60 (ATmega branch)
- Arduino UNO [R4 WiFi](https://github.com/arduino/ArduinoCore-renesas)
- Arduino Nano 33 IoT, MKR WIFI 1010
- Arduino Nano 33 IoT, MKR WIFI 1010 (requires [WiFiNINA](https://github.com/arduino-libraries/WiFiNINA/) library)
- Seeeduino XIAO, Seeeduino Wio Terminal (requires [rpcWiFi](https://github.com/Seeed-Studio/Seeed_Arduino_rpcWiFi) library)

###### Note: ######

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* WebSocketClient.ino
*
* Created on: 10.08.2024
*
*/

#include <Arduino.h>
#include <rpcWiFi.h>
#include <WiFiMulti.h>
#include <WebSocketsClient.h>

WebSocketsClient webSocket;
WiFiMulti wifiMulti;

#define USE_SERIAL Serial

void hexdump(const void *mem, uint32_t len, uint8_t cols = 16) {
const uint8_t* src = (const uint8_t*) mem;
USE_SERIAL.printf("\n[HEXDUMP] Address: 0x%08X len: 0x%X (%d)", (ptrdiff_t)src, len, len);
for(uint32_t i = 0; i < len; i++) {
if(i % cols == 0) {
USE_SERIAL.printf("\n[0x%08X] 0x%08X: ", (ptrdiff_t)src, i);
}
USE_SERIAL.printf("%02X ", *src);
src++;
}
USE_SERIAL.printf("\n");
}

void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {

switch(type) {
case WStype_DISCONNECTED:
USE_SERIAL.printf("[WSc] Disconnected!\n");
break;
case WStype_CONNECTED:
USE_SERIAL.printf("[WSc] Connected to url: %s\n", payload);

// send message to server when Connected
webSocket.sendTXT("Connected");
break;
case WStype_TEXT:
USE_SERIAL.printf("[WSc] get text: %s\n", payload);

// send message to server
// webSocket.sendTXT("message here");
break;
case WStype_BIN:
USE_SERIAL.printf("[WSc] get binary length: %u\n", length);
hexdump(payload, length);

// 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_PONG:
case WStype_PING:
case WStype_FRAGMENT_FIN:
break;
}

}

void setup() {
// USE_SERIAL.begin(921600);
USE_SERIAL.begin(115200);

USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();

for(uint8_t t = 4; t > 0; t--) {
USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t);
USE_SERIAL.flush();
delay(1000);
}

wifiMulti.addAP("SSID", "passpasspass");

//WiFi.disconnect();
while(wifiMulti.run() != WL_CONNECTED) {
delay(100);
}

// server address, port and URL
webSocket.begin("192.168.0.123", 81, "/");

// event handler
webSocket.onEvent(webSocketEvent);

// use HTTP Basic Authorization this is optional remove if not needed
webSocket.setAuthorization("user", "Password");

// try ever 5000 again if connection has failed
webSocket.setReconnectInterval(5000);

}

void loop() {
webSocket.loop();
}
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"keywords": "wifi, http, web, server, client, websocket",
"license": "LGPL-2.1",
"name": "WebSockets",
"platforms": "atmelavr, espressif8266, espressif32, raspberrypi, renesas_uno",
"platforms": "*",
"repository": {
"type": "git",
"url": "https://github.com/Links2004/arduinoWebSockets.git"
Expand Down
2 changes: 1 addition & 1 deletion src/SocketIOclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,4 @@ void SocketIOclient::handleCbEvent(WStype_t type, uint8_t * payload, size_t leng
case WStype_PONG:
break;
}
}
}
4 changes: 3 additions & 1 deletion src/SocketIOclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ class SocketIOclient : protected WebSocketsClient {
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);
#ifndef SSL_AXTLS
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);
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);
void setSSLClientCertKey(const char * clientCert = NULL, const char * clientPrivateKey = NULL);
#if defined(SSL_BARESSL)
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);
void setSSLClientCertKey(BearSSL::X509List * clientCert = NULL, BearSSL::PrivateKey * clientPrivateKey = NULL);
#endif
#endif
#endif
bool isConnected(void);
Expand Down
32 changes: 27 additions & 5 deletions src/WebSockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@
#define WEBSOCKETS_YIELD() yield()
#define WEBSOCKETS_YIELD_MORE() delay(1)

#elif defined(WIO_TERMINAL) || defined(SEEED_XIAO_M0)

#define WEBSOCKETS_MAX_DATA_SIZE (15 * 1024)
#define WEBSOCKETS_YIELD() yield()
#define WEBSOCKETS_YIELD_MORE() delay(1)

#else

// atmega328p has only 2KB ram!
Expand All @@ -128,7 +134,7 @@
#define NETWORK_RP2040 (6)
#define NETWORK_UNOWIFIR4 (7)
#define NETWORK_WIFI_NINA (8)

#define NETWORK_SAMD_SEED (9)

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

#elif defined(WIO_TERMINAL) || defined(SEEED_XIAO_M0)
#define WEBSOCKETS_NETWORK_TYPE NETWORK_SAMD_SEED

#else
#define WEBSOCKETS_NETWORK_TYPE NETWORK_W5100

Expand Down Expand Up @@ -248,10 +257,6 @@
#elif(WEBSOCKETS_NETWORK_TYPE == NETWORK_UNOWIFIR4)

#include <WiFiS3.h>

#define WEBSOCKETS_NETWORK_CLASS WiFiClient
#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer

#define WEBSOCKETS_NETWORK_CLASS WiFiClient
#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer

Expand All @@ -264,6 +269,23 @@

#define WEBSOCKETS_NETWORK_CLASS WiFiClient
#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer
#define WEBSOCKETS_NETWORK_SSL_CLASS WiFiSSLClient

#elif(WEBSOCKETS_NETWORK_TYPE == NETWORK_SAMD_SEED)
#if __has_include(<rpcWiFi.h>) && __has_include(<rpcWiFiClientSecure.h>)
#include <rpcWiFi.h>
#include <rpcWiFiClientSecure.h>
#else
#error "Please install rpcWiFi library!"
#endif

#define WEBSOCKETS_NETWORK_CLASS WiFiClient
#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer
#define WEBSOCKETS_NETWORK_SSL_CLASS WiFiClientSecure

#define WEBSOCKETS_NETWORK_CLASS WiFiClient
#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer

#else
#error "no network type selected!"
#endif
Expand Down
Loading

0 comments on commit 899cfbd

Please sign in to comment.