Skip to content
This repository was archived by the owner on Jan 29, 2023. It is now read-only.

Commit 2c37735

Browse files
authored
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`
1 parent d48e279 commit 2c37735

File tree

5 files changed

+868
-13
lines changed

5 files changed

+868
-13
lines changed

examples/Generic/WiFiNINA/Generic_WebSocketClientSocketIO_WiFiNINA/Generic_WebSocketClientSocketIO_WiFiNINA.ino

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ SocketIOclient socketIO;
3838
IPAddress clientIP(192, 168, 2, 225);
3939

4040
// Select the IP address according to your local network
41-
IPAddress serverIP(192, 168, 2, 51);
42-
uint16_t serverPort = 3000;
41+
IPAddress serverIP(192, 168, 2, 30);
42+
uint16_t serverPort = 8080;
4343

4444
int status = WL_IDLE_STATUS;
4545

@@ -127,7 +127,6 @@ void printWifiStatus()
127127
Serial.println(" dBm");
128128
}
129129

130-
131130
void setup()
132131
{
133132
// Serial.begin(921600);
@@ -137,16 +136,6 @@ void setup()
137136
Serial.print("\nStart Generic_WebSocketClientSocketIO_WiFiNINA on "); Serial.println(BOARD_NAME);
138137
Serial.println(WEBSOCKETS_GENERIC_VERSION);
139138

140-
Serial.println("Used/default SPI pinout:");
141-
Serial.print("MOSI:");
142-
Serial.println(MOSI);
143-
Serial.print("MISO:");
144-
Serial.println(MISO);
145-
Serial.print("SCK:");
146-
Serial.println(SCK);
147-
Serial.print("SS:");
148-
Serial.println(SS);
149-
150139
// check for the WiFi module:
151140
if (WiFi.status() == WL_NO_MODULE)
152141
{
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
/****************************************************************************************************************************
2+
WebSocketClient_RP2040W.ino
3+
For RP2040W boards using CYC43439 WiFi
4+
5+
Blynk_WiFiNINA_WM is a library for the Mega, Teensy, SAM DUE, nRF52, STM32 and SAMD boards
6+
(https://github.com/khoih-prog/Blynk_WiFiNINA_WM) to enable easy configuration/reconfiguration and
7+
autoconnect/autoreconnect of WiFiNINA/Blynk
8+
9+
Based on and modified from WebSockets libarary https://github.com/Links2004/arduinoWebSockets
10+
to support other boards such as SAMD21, SAMD51, Adafruit's nRF52 boards, etc.
11+
12+
Built by Khoi Hoang https://github.com/khoih-prog/WebSockets_Generic
13+
Licensed under MIT license
14+
15+
Created on: 24.05.2015
16+
Author: Markus Sattler
17+
*****************************************************************************************************************************/
18+
19+
#if ( defined(ARDUINO_RASPBERRY_PI_PICO_W) )
20+
#if defined(WEBSOCKETS_NETWORK_TYPE)
21+
#undef WEBSOCKETS_NETWORK_TYPE
22+
#endif
23+
#define WEBSOCKETS_NETWORK_TYPE NETWORK_RP2040W_WIFI
24+
#else
25+
#error This code is intended to run only on the RP2040W boards ! Please check your Tools->Board setting.
26+
#endif
27+
28+
#define _WEBSOCKETS_LOGLEVEL_ 2
29+
30+
#include <WiFi.h>
31+
32+
#include <WebSocketsClient_Generic.h>
33+
34+
WebSocketsClient webSocket;
35+
36+
int status = WL_IDLE_STATUS;
37+
38+
// Deprecated echo.websocket.org to be replaced
39+
#define WS_SERVER "wss://echo.websocket.org"
40+
#define SSL_PORT 443
41+
42+
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
43+
44+
char ssid[] = "your_ssid"; // your network SSID (name)
45+
char pass[] = "12345678"; // your network password (use for WPA, or use as key for WEP), length must be 8+
46+
47+
bool alreadyConnected = false;
48+
49+
void webSocketEvent(const WStype_t& type, uint8_t * payload, const size_t& length)
50+
{
51+
switch (type)
52+
{
53+
case WStype_DISCONNECTED:
54+
if (alreadyConnected)
55+
{
56+
Serial.println("[WSc] Disconnected!");
57+
alreadyConnected = false;
58+
}
59+
60+
break;
61+
62+
case WStype_CONNECTED:
63+
{
64+
alreadyConnected = true;
65+
66+
Serial.print("[WSc] Connected to url: ");
67+
Serial.println((char *) payload);
68+
69+
// send message to server when Connected
70+
webSocket.sendTXT("Connected");
71+
}
72+
73+
break;
74+
75+
case WStype_TEXT:
76+
Serial.print("[WSc] get text: ");
77+
Serial.println((char *) payload);
78+
79+
// send message to server
80+
webSocket.sendTXT("message here");
81+
82+
break;
83+
84+
case WStype_BIN:
85+
Serial.print("[WSc] get binary length: ");
86+
Serial.println(length);
87+
88+
// KH, To check
89+
// hexdump(payload, length);
90+
91+
// send data to server
92+
webSocket.sendBIN(payload, length);
93+
94+
break;
95+
96+
case WStype_PING:
97+
// pong will be send automatically
98+
Serial.println("[WSc] get ping");
99+
100+
break;
101+
102+
case WStype_PONG:
103+
// answer to a ping we send
104+
Serial.println("[WSc] get pong");
105+
106+
break;
107+
108+
default:
109+
break;
110+
}
111+
}
112+
113+
void printWifiStatus()
114+
{
115+
// print the SSID of the network you're attached to:
116+
Serial.print("SSID: ");
117+
Serial.println(WiFi.SSID());
118+
119+
// print your board's IP address:
120+
IPAddress ip = WiFi.localIP();
121+
Serial.print("WebSockets Client IP Address: ");
122+
Serial.println(ip);
123+
124+
// print the received signal strength:
125+
long rssi = WiFi.RSSI();
126+
Serial.print("signal strength (RSSI):");
127+
Serial.print(rssi);
128+
Serial.println(" dBm");
129+
}
130+
131+
void setup()
132+
{
133+
//Initialize serial and wait for port to open:
134+
Serial.begin(115200);
135+
while (!Serial);
136+
137+
Serial.print("\nStart WebSocketClientSSL_RP2040W on "); Serial.println(BOARD_NAME);
138+
Serial.println(WEBSOCKETS_GENERIC_VERSION);
139+
140+
///////////////////////////////////
141+
142+
// check for the WiFi module:
143+
if (WiFi.status() == WL_NO_MODULE)
144+
{
145+
Serial.println("Communication with WiFi module failed!");
146+
// don't continue
147+
while (true);
148+
}
149+
150+
Serial.print(F("Connecting to SSID: "));
151+
Serial.println(ssid);
152+
153+
status = WiFi.begin(ssid, pass);
154+
155+
delay(1000);
156+
157+
// attempt to connect to WiFi network
158+
while ( status != WL_CONNECTED)
159+
{
160+
delay(500);
161+
162+
// Connect to WPA/WPA2 network
163+
status = WiFi.status();
164+
}
165+
166+
printWifiStatus();
167+
168+
///////////////////////////////////
169+
170+
// server address, port and URL
171+
Serial.print("WebSockets Server : ");
172+
Serial.println(WS_SERVER);
173+
174+
// server address, port and URL
175+
webSocket.beginSSL(WS_SERVER, SSL_PORT);
176+
177+
// event handler
178+
webSocket.onEvent(webSocketEvent);
179+
180+
// server address, port and URL
181+
Serial.print("Connecting to WebSockets Server @ ");
182+
Serial.println(WS_SERVER);
183+
}
184+
185+
void loop()
186+
{
187+
webSocket.loop();
188+
}

0 commit comments

Comments
 (0)