Skip to content

Commit 28e45a9

Browse files
committed
Add initial AsyncUDP
1 parent fd5cf3d commit 28e45a9

File tree

8 files changed

+1207
-0
lines changed

8 files changed

+1207
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include "WiFi.h"
2+
#include "AsyncUDP.h"
3+
4+
const char * ssid = "***********";
5+
const char * password = "***********";
6+
7+
AsyncUDP udp;
8+
9+
void setup()
10+
{
11+
Serial.begin(115200);
12+
WiFi.mode(WIFI_STA);
13+
WiFi.begin(ssid, password);
14+
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
15+
Serial.println("WiFi Failed");
16+
while(1) {
17+
delay(1000);
18+
}
19+
}
20+
if(udp.connect(IPAddress(192,168,1,100), 1234)) {
21+
Serial.println("UDP connected");
22+
udp.onPacket([](AsyncUDPPacket packet) {
23+
Serial.print("UDP Packet Type: ");
24+
Serial.print(packet.isBroadcast()?"Broadcast":packet.isMulticast()?"Multicast":"Unicast");
25+
Serial.print(", From: ");
26+
Serial.print(packet.remoteIP());
27+
Serial.print(":");
28+
Serial.print(packet.remotePort());
29+
Serial.print(", To: ");
30+
Serial.print(packet.localIP());
31+
Serial.print(":");
32+
Serial.print(packet.localPort());
33+
Serial.print(", Length: ");
34+
Serial.print(packet.length());
35+
Serial.print(", Data: ");
36+
Serial.write(packet.data(), packet.length());
37+
Serial.println();
38+
//reply to the client
39+
packet.printf("Got %u bytes of data", packet.length());
40+
});
41+
//Send unicast
42+
udp.print("Hello Server!");
43+
}
44+
}
45+
46+
void loop()
47+
{
48+
delay(1000);
49+
//Send broadcast on port 1234
50+
udp.broadcastTo("Anyone here?", 1234);
51+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include "WiFi.h"
2+
#include "AsyncUDP.h"
3+
4+
const char * ssid = "***********";
5+
const char * password = "***********";
6+
7+
AsyncUDP udp;
8+
9+
void setup()
10+
{
11+
Serial.begin(115200);
12+
WiFi.mode(WIFI_STA);
13+
WiFi.begin(ssid, password);
14+
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
15+
Serial.println("WiFi Failed");
16+
while(1) {
17+
delay(1000);
18+
}
19+
}
20+
if(udp.listenMulticast(IPAddress(239,1,2,3), 1234)) {
21+
Serial.print("UDP Listening on IP: ");
22+
Serial.println(WiFi.localIP());
23+
udp.onPacket([](AsyncUDPPacket packet) {
24+
Serial.print("UDP Packet Type: ");
25+
Serial.print(packet.isBroadcast()?"Broadcast":packet.isMulticast()?"Multicast":"Unicast");
26+
Serial.print(", From: ");
27+
Serial.print(packet.remoteIP());
28+
Serial.print(":");
29+
Serial.print(packet.remotePort());
30+
Serial.print(", To: ");
31+
Serial.print(packet.localIP());
32+
Serial.print(":");
33+
Serial.print(packet.localPort());
34+
Serial.print(", Length: ");
35+
Serial.print(packet.length());
36+
Serial.print(", Data: ");
37+
Serial.write(packet.data(), packet.length());
38+
Serial.println();
39+
//reply to the client
40+
packet.printf("Got %u bytes of data", packet.length());
41+
});
42+
//Send multicast
43+
udp.print("Hello!");
44+
}
45+
}
46+
47+
void loop()
48+
{
49+
delay(1000);
50+
//Send multicast
51+
udp.print("Anyone here?");
52+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include "WiFi.h"
2+
#include "AsyncUDP.h"
3+
4+
const char * ssid = "***********";
5+
const char * password = "***********";
6+
7+
AsyncUDP udp;
8+
9+
void setup()
10+
{
11+
Serial.begin(115200);
12+
WiFi.mode(WIFI_STA);
13+
WiFi.begin(ssid, password);
14+
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
15+
Serial.println("WiFi Failed");
16+
while(1) {
17+
delay(1000);
18+
}
19+
}
20+
if(udp.listen(1234)) {
21+
Serial.print("UDP Listening on IP: ");
22+
Serial.println(WiFi.localIP());
23+
udp.onPacket([](AsyncUDPPacket packet) {
24+
Serial.print("UDP Packet Type: ");
25+
Serial.print(packet.isBroadcast()?"Broadcast":packet.isMulticast()?"Multicast":"Unicast");
26+
Serial.print(", From: ");
27+
Serial.print(packet.remoteIP());
28+
Serial.print(":");
29+
Serial.print(packet.remotePort());
30+
Serial.print(", To: ");
31+
Serial.print(packet.localIP());
32+
Serial.print(":");
33+
Serial.print(packet.localPort());
34+
Serial.print(", Length: ");
35+
Serial.print(packet.length());
36+
Serial.print(", Data: ");
37+
Serial.write(packet.data(), packet.length());
38+
Serial.println();
39+
//reply to the client
40+
packet.printf("Got %u bytes of data", packet.length());
41+
});
42+
}
43+
}
44+
45+
void loop()
46+
{
47+
delay(1000);
48+
//Send broadcast
49+
udp.broadcast("Anyone here?");
50+
}

libraries/AsyncUDP/keywords.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#######################################
2+
# Syntax Coloring Map For Ultrasound
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
AsyncUDP KEYWORD1
10+
AsyncUDPPacket KEYWORD1
11+
12+
#######################################
13+
# Methods and Functions (KEYWORD2)
14+
#######################################
15+
16+
connect KEYWORD2
17+
connected KEYWORD2
18+
listen KEYWORD2
19+
listenMulticast KEYWORD2
20+
close KEYWORD2
21+
write KEYWORD2
22+
broadcast KEYWORD2
23+
onPacket KEYWORD2
24+
data KEYWORD2
25+
length KEYWORD2
26+
localIP KEYWORD2
27+
localPort KEYWORD2
28+
remoteIP KEYWORD2
29+
remotePort KEYWORD2
30+
31+
#######################################
32+
# Constants (LITERAL1)
33+
#######################################

libraries/AsyncUDP/library.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name":"AsyncUDP",
3+
"description":"Asynchronous UDP Library for ESP32",
4+
"keywords":"async,udp,server,client,multicast,broadcast",
5+
"authors":
6+
{
7+
"name": "Hristo Gochkov",
8+
"maintainer": true
9+
},
10+
"repository":
11+
{
12+
"type": "git",
13+
"url": "https://github.com/me-no-dev/ESPAsyncUDP.git"
14+
},
15+
"frameworks": "arduino",
16+
"platforms":"espressif"
17+
}

libraries/AsyncUDP/library.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=ESP32 Async UDP
2+
version=1.0.0
3+
author=Me-No-Dev
4+
maintainer=Me-No-Dev
5+
sentence=Async UDP Library for ESP32
6+
paragraph=Async UDP Library for ESP32
7+
category=Other
8+
url=https://github.com/me-no-dev/ESPAsyncUDP
9+
architectures=*

0 commit comments

Comments
 (0)