This repository has been archived by the owner on Jan 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v2.16.0 add support to RP2040 and RP2040W boards
### Release v2.16.0 1. Add support to **RP2040-based boards, such as Nano_RP2040_Connect, RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040**, using WiFiNINA or Ethernet 2. Add `WS` and `BearSSL WSS` support to `RP2040W` using `CYW43439 WiFi` with `arduino-pico` core 3. Optional user-defined - `WEBSOCKETS_TCP_TIMEOUT`, default 5,000ms - `EIO_HEARTBEAT_INTERVAL`, default 20,000ms - `SIO_PING_INTERVAL`, default 60,000ms - `SIO_PONG_TIMEOUT`, default 90,000ms - `SIO_DISCONNECT_TIMEOUT_COUNT`, default 5 4. Update `Packages' Patches`
- Loading branch information
1 parent
d48e279
commit 2c37735
Showing
5 changed files
with
868 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
188 changes: 188 additions & 0 deletions
188
examples/RP2040W/WebSocketClientSSL_RP2040W/WebSocketClientSSL_RP2040W.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
/**************************************************************************************************************************** | ||
WebSocketClient_RP2040W.ino | ||
For RP2040W boards using CYC43439 WiFi | ||
Blynk_WiFiNINA_WM is a library for the Mega, Teensy, SAM DUE, nRF52, STM32 and SAMD boards | ||
(https://github.com/khoih-prog/Blynk_WiFiNINA_WM) to enable easy configuration/reconfiguration and | ||
autoconnect/autoreconnect of WiFiNINA/Blynk | ||
Based on and modified from WebSockets libarary https://github.com/Links2004/arduinoWebSockets | ||
to support other boards such as SAMD21, SAMD51, Adafruit's nRF52 boards, etc. | ||
Built by Khoi Hoang https://github.com/khoih-prog/WebSockets_Generic | ||
Licensed under MIT license | ||
Created on: 24.05.2015 | ||
Author: Markus Sattler | ||
*****************************************************************************************************************************/ | ||
|
||
#if ( defined(ARDUINO_RASPBERRY_PI_PICO_W) ) | ||
#if defined(WEBSOCKETS_NETWORK_TYPE) | ||
#undef WEBSOCKETS_NETWORK_TYPE | ||
#endif | ||
#define WEBSOCKETS_NETWORK_TYPE NETWORK_RP2040W_WIFI | ||
#else | ||
#error This code is intended to run only on the RP2040W boards ! Please check your Tools->Board setting. | ||
#endif | ||
|
||
#define _WEBSOCKETS_LOGLEVEL_ 2 | ||
|
||
#include <WiFi.h> | ||
|
||
#include <WebSocketsClient_Generic.h> | ||
|
||
WebSocketsClient webSocket; | ||
|
||
int status = WL_IDLE_STATUS; | ||
|
||
// Deprecated echo.websocket.org to be replaced | ||
#define WS_SERVER "wss://echo.websocket.org" | ||
#define SSL_PORT 443 | ||
|
||
///////please enter your sensitive data in the Secret tab/arduino_secrets.h | ||
|
||
char ssid[] = "your_ssid"; // your network SSID (name) | ||
char pass[] = "12345678"; // your network password (use for WPA, or use as key for WEP), length must be 8+ | ||
|
||
bool alreadyConnected = false; | ||
|
||
void webSocketEvent(const WStype_t& type, uint8_t * payload, const size_t& length) | ||
{ | ||
switch (type) | ||
{ | ||
case WStype_DISCONNECTED: | ||
if (alreadyConnected) | ||
{ | ||
Serial.println("[WSc] Disconnected!"); | ||
alreadyConnected = false; | ||
} | ||
|
||
break; | ||
|
||
case WStype_CONNECTED: | ||
{ | ||
alreadyConnected = true; | ||
|
||
Serial.print("[WSc] Connected to url: "); | ||
Serial.println((char *) payload); | ||
|
||
// 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: | ||
Serial.print("[WSc] get binary length: "); | ||
Serial.println(length); | ||
|
||
// KH, To check | ||
// hexdump(payload, length); | ||
|
||
// send data to server | ||
webSocket.sendBIN(payload, length); | ||
|
||
break; | ||
|
||
case WStype_PING: | ||
// pong will be send automatically | ||
Serial.println("[WSc] get ping"); | ||
|
||
break; | ||
|
||
case WStype_PONG: | ||
// answer to a ping we send | ||
Serial.println("[WSc] get pong"); | ||
|
||
break; | ||
|
||
default: | ||
break; | ||
} | ||
} | ||
|
||
void printWifiStatus() | ||
{ | ||
// print the SSID of the network you're attached to: | ||
Serial.print("SSID: "); | ||
Serial.println(WiFi.SSID()); | ||
|
||
// print your board's IP address: | ||
IPAddress ip = WiFi.localIP(); | ||
Serial.print("WebSockets Client IP Address: "); | ||
Serial.println(ip); | ||
|
||
// print the received signal strength: | ||
long rssi = WiFi.RSSI(); | ||
Serial.print("signal strength (RSSI):"); | ||
Serial.print(rssi); | ||
Serial.println(" dBm"); | ||
} | ||
|
||
void setup() | ||
{ | ||
//Initialize serial and wait for port to open: | ||
Serial.begin(115200); | ||
while (!Serial); | ||
|
||
Serial.print("\nStart WebSocketClientSSL_RP2040W on "); Serial.println(BOARD_NAME); | ||
Serial.println(WEBSOCKETS_GENERIC_VERSION); | ||
|
||
/////////////////////////////////// | ||
|
||
// check for the WiFi module: | ||
if (WiFi.status() == WL_NO_MODULE) | ||
{ | ||
Serial.println("Communication with WiFi module failed!"); | ||
// don't continue | ||
while (true); | ||
} | ||
|
||
Serial.print(F("Connecting to SSID: ")); | ||
Serial.println(ssid); | ||
|
||
status = WiFi.begin(ssid, pass); | ||
|
||
delay(1000); | ||
|
||
// attempt to connect to WiFi network | ||
while ( status != WL_CONNECTED) | ||
{ | ||
delay(500); | ||
|
||
// Connect to WPA/WPA2 network | ||
status = WiFi.status(); | ||
} | ||
|
||
printWifiStatus(); | ||
|
||
/////////////////////////////////// | ||
|
||
// server address, port and URL | ||
Serial.print("WebSockets Server : "); | ||
Serial.println(WS_SERVER); | ||
|
||
// server address, port and URL | ||
webSocket.beginSSL(WS_SERVER, SSL_PORT); | ||
|
||
// event handler | ||
webSocket.onEvent(webSocketEvent); | ||
|
||
// server address, port and URL | ||
Serial.print("Connecting to WebSockets Server @ "); | ||
Serial.println(WS_SERVER); | ||
} | ||
|
||
void loop() | ||
{ | ||
webSocket.loop(); | ||
} |
Oops, something went wrong.