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

Commit 0e4b844

Browse files
authored
v1.0.0 for RP2040W with CYW43439 WiFi
### Initial Releases v1.0.0 1. Initial coding to support **RASPBERRY_PI_PICO_W with CYW43439 WiFi**, using [**arduino-pico core v2.4.0+**](https://github.com/earlephilhower/arduino-pico)
1 parent 8a0b83a commit 0e4b844

File tree

11 files changed

+913
-0
lines changed

11 files changed

+913
-0
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/****************************************************************************************************************************
2+
AsyncUDPClient.ino
3+
4+
For RP2040W with CYW43439 WiFi
5+
6+
AsyncUDP_RP2040W is a library for the RP2040W with CYW43439 WiFi
7+
8+
Based on and modified from ESPAsyncUDP (https://github.com/me-no-dev/ESPAsyncUDP)
9+
Built by Khoi Hoang https://github.com/khoih-prog/AsyncUDP_RP2040W
10+
*****************************************************************************************************************************/
11+
12+
#if !( defined(ARDUINO_RASPBERRY_PI_PICO_W) )
13+
#error For RASPBERRY_PI_PICO_W only
14+
#endif
15+
16+
#include <WiFi.h>
17+
18+
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
19+
#include <AsyncUDP_RP2040W.h> // https://github.com/khoih-prog/AsyncUDP_RP2040W
20+
21+
char ssid[] = "your_ssid"; // your network SSID (name)
22+
char pass[] = "12345678"; // your network password (use for WPA, or use as key for WEP), length must be 8+
23+
24+
AsyncUDP udp;
25+
26+
int status = WL_IDLE_STATUS;
27+
28+
void printWifiStatus()
29+
{
30+
// print the SSID of the network you're attached to:
31+
Serial.print("SSID: ");
32+
Serial.println(WiFi.SSID());
33+
34+
// print your board's IP address:
35+
IPAddress ip = WiFi.localIP();
36+
Serial.print("Local IP Address: ");
37+
Serial.println(ip);
38+
39+
// print the received signal strength:
40+
long rssi = WiFi.RSSI();
41+
Serial.print("signal strength (RSSI):");
42+
Serial.print(rssi);
43+
Serial.println(" dBm");
44+
}
45+
46+
void setup()
47+
{
48+
Serial.begin(115200);
49+
while (!Serial && millis() < 5000);
50+
51+
Serial.print("\nStart AsyncUDPClient on "); Serial.println(BOARD_NAME);
52+
Serial.println(ASYNC_UDP_RP2040W_VERSION);
53+
54+
///////////////////////////////////
55+
56+
// check for the WiFi module:
57+
if (WiFi.status() == WL_NO_MODULE)
58+
{
59+
Serial.println("Communication with WiFi module failed!");
60+
// don't continue
61+
while (true);
62+
}
63+
64+
Serial.print(F("Connecting to SSID: "));
65+
Serial.println(ssid);
66+
67+
status = WiFi.begin(ssid, pass);
68+
69+
delay(1000);
70+
71+
// attempt to connect to WiFi network
72+
while ( status != WL_CONNECTED)
73+
{
74+
delay(500);
75+
76+
// Connect to WPA/WPA2 network
77+
status = WiFi.status();
78+
}
79+
80+
printWifiStatus();
81+
82+
///////////////////////////////////
83+
84+
if (udp.connect(IPAddress(192, 168, 1, 100), 1234))
85+
{
86+
Serial.println("UDP connected");
87+
88+
udp.onPacket([](AsyncUDPPacket packet)
89+
{
90+
Serial.print("UDP Packet Type: ");
91+
Serial.print(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast" : "Unicast");
92+
Serial.print(", From: ");
93+
Serial.print(packet.remoteIP());
94+
Serial.print(":");
95+
Serial.print(packet.remotePort());
96+
Serial.print(", To: ");
97+
Serial.print(packet.localIP());
98+
Serial.print(":");
99+
Serial.print(packet.localPort());
100+
Serial.print(", Length: ");
101+
Serial.print(packet.length());
102+
Serial.print(", Data: ");
103+
Serial.write(packet.data(), packet.length());
104+
Serial.println();
105+
//reply to the client
106+
packet.printf("Got %u bytes of data", packet.length());
107+
});
108+
109+
//Send unicast
110+
udp.print("Hello Server!");
111+
}
112+
}
113+
114+
void loop()
115+
{
116+
delay(1000);
117+
//Send broadcast on port 1234
118+
udp.broadcastTo("Anyone here?", 1234);
119+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/****************************************************************************************************************************
2+
AsyncUDPMulticastServer.ino
3+
4+
AsyncUDP_RP2040W is a library for the RP2040W with CYW43439 WiFi
5+
6+
Based on and modified from ESPAsyncUDP (https://github.com/me-no-dev/ESPAsyncUDP)
7+
Built by Khoi Hoang https://github.com/khoih-prog/AsyncUDP_RP2040W
8+
*****************************************************************************************************************************/
9+
10+
#if !( defined(ARDUINO_RASPBERRY_PI_PICO_W) )
11+
#error For RASPBERRY_PI_PICO_W only
12+
#endif
13+
14+
#include <WiFi.h>
15+
16+
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
17+
#include <AsyncUDP_RP2040W.h> // https://github.com/khoih-prog/AsyncUDP_RP2040W
18+
19+
char ssid[] = "your_ssid"; // your network SSID (name)
20+
char pass[] = "12345678"; // your network password (use for WPA, or use as key for WEP), length must be 8+
21+
22+
AsyncUDP udp;
23+
24+
int status = WL_IDLE_STATUS;
25+
26+
#define BUF_SZ 32
27+
28+
char buf[BUF_SZ];
29+
30+
void parsePacket(AsyncUDPPacket packet)
31+
{
32+
Serial.print("UDP Packet Type: ");
33+
Serial.print(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast" : "Unicast");
34+
Serial.print(", From: ");
35+
Serial.print(packet.remoteIP());
36+
Serial.print(":");
37+
Serial.print(packet.remotePort());
38+
Serial.print(", To: ");
39+
Serial.print(packet.localIP());
40+
Serial.print(":");
41+
Serial.print(packet.localPort());
42+
Serial.print(", Length: ");
43+
Serial.print(packet.length());
44+
Serial.print(", Data: ");
45+
Serial.write(packet.data(), packet.length());
46+
Serial.println();
47+
48+
snprintf(buf, sizeof(buf) -1, "Got %u bytes of data", packet.length());
49+
//reply to the client
50+
// size_t write(const uint8_t *data, size_t len);
51+
packet.write((uint8_t*) buf, strlen(buf));
52+
}
53+
54+
void printWifiStatus()
55+
{
56+
// print the SSID of the network you're attached to:
57+
Serial.print("SSID: ");
58+
Serial.println(WiFi.SSID());
59+
60+
// print your board's IP address:
61+
IPAddress ip = WiFi.localIP();
62+
Serial.print("Local IP Address: ");
63+
Serial.println(ip);
64+
65+
// print the received signal strength:
66+
long rssi = WiFi.RSSI();
67+
Serial.print("signal strength (RSSI):");
68+
Serial.print(rssi);
69+
Serial.println(" dBm");
70+
}
71+
72+
void setup()
73+
{
74+
Serial.begin(115200);
75+
while (!Serial && millis() < 5000);
76+
77+
Serial.print("\nStart AsyncUDPMulticastServer on "); Serial.println(BOARD_NAME);
78+
Serial.println(ASYNC_UDP_RP2040W_VERSION);
79+
80+
///////////////////////////////////
81+
82+
// check for the WiFi module:
83+
if (WiFi.status() == WL_NO_MODULE)
84+
{
85+
Serial.println("Communication with WiFi module failed!");
86+
// don't continue
87+
while (true);
88+
}
89+
90+
Serial.print(F("Connecting to SSID: "));
91+
Serial.println(ssid);
92+
93+
status = WiFi.begin(ssid, pass);
94+
95+
delay(1000);
96+
97+
// attempt to connect to WiFi network
98+
while ( status != WL_CONNECTED)
99+
{
100+
delay(500);
101+
102+
// Connect to WPA/WPA2 network
103+
status = WiFi.status();
104+
}
105+
106+
printWifiStatus();
107+
108+
///////////////////////////////////
109+
110+
if (udp.listenMulticast(IPAddress(239, 1, 2, 3), 1234))
111+
{
112+
Serial.print("UDP Listening on IP: ");
113+
Serial.println(WiFi.localIP());
114+
115+
udp.onPacket([](AsyncUDPPacket packet)
116+
{
117+
parsePacket(packet);
118+
});
119+
120+
//Send multicast
121+
udp.print("Hello!");
122+
}
123+
}
124+
125+
void loop()
126+
{
127+
delay(1000);
128+
//Send multicast
129+
udp.print("Anyone here?");
130+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/****************************************************************************************************************************
2+
Async_UdpServer.ino
3+
4+
AsyncUDP_RP2040W is a library for the RP2040W with CYW43439 WiFi
5+
6+
Based on and modified from ESPAsyncUDP (https://github.com/me-no-dev/ESPAsyncUDP)
7+
Built by Khoi Hoang https://github.com/khoih-prog/AsyncUDP_RP2040W
8+
*****************************************************************************************************************************/
9+
10+
#if !( defined(ARDUINO_RASPBERRY_PI_PICO_W) )
11+
#error For RASPBERRY_PI_PICO_W only
12+
#endif
13+
14+
#include <WiFi.h>
15+
16+
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
17+
#include <AsyncUDP_RP2040W.h> // https://github.com/khoih-prog/AsyncUDP_RP2040W
18+
19+
char ssid[] = "your_ssid"; // your network SSID (name)
20+
char pass[] = "12345678"; // your network password (use for WPA, or use as key for WEP), length must be 8+
21+
22+
AsyncUDP udp;
23+
24+
int status = WL_IDLE_STATUS;
25+
26+
#define BUF_SZ 32
27+
28+
char buf[BUF_SZ];
29+
30+
void printWifiStatus()
31+
{
32+
// print the SSID of the network you're attached to:
33+
Serial.print("SSID: ");
34+
Serial.println(WiFi.SSID());
35+
36+
// print your board's IP address:
37+
IPAddress ip = WiFi.localIP();
38+
Serial.print("Local IP Address: ");
39+
Serial.println(ip);
40+
41+
// print the received signal strength:
42+
long rssi = WiFi.RSSI();
43+
Serial.print("signal strength (RSSI):");
44+
Serial.print(rssi);
45+
Serial.println(" dBm");
46+
}
47+
48+
void setup()
49+
{
50+
Serial.begin(115200);
51+
while (!Serial && millis() < 5000);
52+
53+
Serial.print("\nStart Async_UdpServer on "); Serial.println(BOARD_NAME);
54+
Serial.println(ASYNC_UDP_RP2040W_VERSION);
55+
56+
///////////////////////////////////
57+
58+
// check for the WiFi module:
59+
if (WiFi.status() == WL_NO_MODULE)
60+
{
61+
Serial.println("Communication with WiFi module failed!");
62+
// don't continue
63+
while (true);
64+
}
65+
66+
Serial.print(F("Connecting to SSID: "));
67+
Serial.println(ssid);
68+
69+
status = WiFi.begin(ssid, pass);
70+
71+
delay(1000);
72+
73+
// attempt to connect to WiFi network
74+
while ( status != WL_CONNECTED)
75+
{
76+
delay(500);
77+
78+
// Connect to WPA/WPA2 network
79+
status = WiFi.status();
80+
}
81+
82+
printWifiStatus();
83+
84+
///////////////////////////////////
85+
86+
if (udp.listen(1234))
87+
{
88+
Serial.print("UDP Listening on IP: ");
89+
Serial.println(WiFi.localIP());
90+
91+
udp.onPacket([](AsyncUDPPacket packet)
92+
{
93+
Serial.print("UDP Packet Type: ");
94+
Serial.print(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast" : "Unicast");
95+
Serial.print(", From: ");
96+
Serial.print(packet.remoteIP());
97+
Serial.print(":");
98+
Serial.print(packet.remotePort());
99+
Serial.print(", To: ");
100+
Serial.print(packet.localIP());
101+
Serial.print(":");
102+
Serial.print(packet.localPort());
103+
Serial.print(", Length: ");
104+
Serial.print(packet.length());
105+
Serial.print(", Data: ");
106+
Serial.write(packet.data(), packet.length());
107+
Serial.println();
108+
109+
snprintf(buf, sizeof(buf) -1, "Got %u bytes of data", packet.length());
110+
//reply to the client
111+
// size_t write(const uint8_t *data, size_t len);
112+
packet.write((uint8_t*) buf, strlen(buf));
113+
});
114+
}
115+
}
116+
117+
void loop()
118+
{
119+
delay(1000);
120+
//Send broadcast
121+
udp.broadcast("Anyone here?");
122+
}

0 commit comments

Comments
 (0)