Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-esp32
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-esp32
Commits
78820f22
Unverified
Commit
78820f22
authored
Apr 04, 2024
by
Lucas Saavedra Vaz
Committed by
GitHub
Apr 04, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ESP-NOW: Fix examples and improve logging (#9455)
parent
dcc30766
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
18 deletions
+26
-18
libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Master/ESP_NOW_Broadcast_Master.ino
...les/ESP_NOW_Broadcast_Master/ESP_NOW_Broadcast_Master.ino
+5
-4
libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Slave/ESP_NOW_Broadcast_Slave.ino
...mples/ESP_NOW_Broadcast_Slave/ESP_NOW_Broadcast_Slave.ino
+7
-6
libraries/ESP_NOW/examples/ESP_NOW_Network/ESP_NOW_Network.ino
...ries/ESP_NOW/examples/ESP_NOW_Network/ESP_NOW_Network.ino
+7
-6
libraries/ESP_NOW/examples/ESP_NOW_Serial/ESP_NOW_Serial.ino
libraries/ESP_NOW/examples/ESP_NOW_Serial/ESP_NOW_Serial.ino
+2
-0
libraries/ESP_NOW/src/ESP32_NOW.h
libraries/ESP_NOW/src/ESP32_NOW.h
+5
-2
No files found.
libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Master/ESP_NOW_Broadcast_Master.ino
View file @
78820f22
...
...
@@ -67,16 +67,17 @@ void setup() {
Serial
.
begin
(
115200
);
while
(
!
Serial
)
delay
(
10
);
// Initialize the Wi-Fi module
WiFi
.
mode
(
WIFI_STA
);
WiFi
.
setChannel
(
ESPNOW_WIFI_CHANNEL
);
while
(
!
WiFi
.
STA
.
started
())
delay
(
100
);
Serial
.
println
(
"ESP-NOW Example - Broadcast Master"
);
Serial
.
println
(
"Wi-Fi parameters:"
);
Serial
.
println
(
" Mode: STA"
);
Serial
.
println
(
" MAC Address: "
+
WiFi
.
macAddress
());
Serial
.
printf
(
" Channel: %d
\n
"
,
ESPNOW_WIFI_CHANNEL
);
// Initialize the Wi-Fi module
WiFi
.
mode
(
WIFI_STA
);
WiFi
.
setChannel
(
ESPNOW_WIFI_CHANNEL
);
// Register the broadcast peer
if
(
!
broadcast_peer
.
begin
())
{
Serial
.
println
(
"Failed to initialize broadcast peer"
);
...
...
libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Slave/ESP_NOW_Broadcast_Slave.ino
View file @
78820f22
...
...
@@ -45,8 +45,8 @@ public:
return
true
;
}
// Function to
print the received messages from the master
void
_
onReceive
(
const
uint8_t
*
data
,
size_t
len
,
bool
broadcast
)
{
// Function to print the received messages from the master
void
onReceive
(
const
uint8_t
*
data
,
size_t
len
,
bool
broadcast
)
{
Serial
.
printf
(
"Received a message from master "
MACSTR
" (%s)
\n
"
,
MAC2STR
(
addr
()),
broadcast
?
"broadcast"
:
"unicast"
);
Serial
.
printf
(
" Message: %s
\n
"
,
(
char
*
)
data
);
}
...
...
@@ -85,16 +85,17 @@ void setup() {
Serial
.
begin
(
115200
);
while
(
!
Serial
)
delay
(
10
);
// Initialize the Wi-Fi module
WiFi
.
mode
(
WIFI_STA
);
WiFi
.
setChannel
(
ESPNOW_WIFI_CHANNEL
);
while
(
!
WiFi
.
STA
.
started
())
delay
(
100
);
Serial
.
println
(
"ESP-NOW Example - Broadcast Slave"
);
Serial
.
println
(
"Wi-Fi parameters:"
);
Serial
.
println
(
" Mode: STA"
);
Serial
.
println
(
" MAC Address: "
+
WiFi
.
macAddress
());
Serial
.
printf
(
" Channel: %d
\n
"
,
ESPNOW_WIFI_CHANNEL
);
// Initialize the Wi-Fi module
WiFi
.
mode
(
WIFI_STA
);
WiFi
.
setChannel
(
ESPNOW_WIFI_CHANNEL
);
// Initialize the ESP-NOW protocol
if
(
!
ESP_NOW
.
begin
())
{
Serial
.
println
(
"Failed to initialize ESP-NOW"
);
...
...
libraries/ESP_NOW/examples/ESP_NOW_Network/ESP_NOW_Network.ino
View file @
78820f22
...
...
@@ -162,10 +162,10 @@ public:
void
onSent
(
bool
success
)
{
bool
broadcast
=
memcmp
(
addr
(),
ESP_NOW
.
BROADCAST_ADDR
,
ESP_NOW_ETH_ALEN
)
==
0
;
if
(
broadcast
)
{
log_
v
(
"Broadcast message reported as sent %s"
,
success
?
"successfully"
:
"unsuccessfully"
);
log_
i
(
"Broadcast message reported as sent %s"
,
success
?
"successfully"
:
"unsuccessfully"
);
}
else
{
log_
v
(
"Unicast message reported as sent %s to peer "
MACSTR
,
success
?
"successfully"
:
"unsuccessfully"
,
MAC2STR
(
addr
()));
log_
i
(
"Unicast message reported as sent %s to peer "
MACSTR
,
success
?
"successfully"
:
"unsuccessfully"
,
MAC2STR
(
addr
()));
}
}
};
...
...
@@ -253,16 +253,17 @@ void setup() {
Serial
.
begin
(
115200
);
while
(
!
Serial
)
delay
(
10
);
// Initialize the Wi-Fi module
WiFi
.
mode
(
WIFI_STA
);
WiFi
.
setChannel
(
ESPNOW_WIFI_CHANNEL
);
while
(
!
WiFi
.
STA
.
started
())
delay
(
100
);
Serial
.
println
(
"ESP-NOW Network Example"
);
Serial
.
println
(
"Wi-Fi parameters:"
);
Serial
.
println
(
" Mode: STA"
);
Serial
.
println
(
" MAC Address: "
+
WiFi
.
macAddress
());
Serial
.
printf
(
" Channel: %d
\n
"
,
ESPNOW_WIFI_CHANNEL
);
// Initialize the Wi-Fi module
WiFi
.
mode
(
WIFI_STA
);
WiFi
.
setChannel
(
ESPNOW_WIFI_CHANNEL
);
// Generate yhis device's priority based on the 3 last bytes of the MAC address
WiFi
.
macAddress
(
self_mac
);
self_priority
=
self_mac
[
3
]
<<
16
|
self_mac
[
4
]
<<
8
|
self_mac
[
5
];
...
...
libraries/ESP_NOW/examples/ESP_NOW_Serial/ESP_NOW_Serial.ino
View file @
78820f22
...
...
@@ -54,6 +54,8 @@ void setup() {
Serial
.
println
(
ESPNOW_WIFI_CHANNEL
);
WiFi
.
setChannel
(
ESPNOW_WIFI_CHANNEL
,
WIFI_SECOND_CHAN_NONE
);
while
(
!
(
WiFi
.
STA
.
started
()
||
WiFi
.
AP
.
started
()))
delay
(
100
);
Serial
.
print
(
"MAC Address: "
);
Serial
.
println
(
ESPNOW_WIFI_MODE
==
WIFI_AP
?
WiFi
.
softAPmacAddress
()
:
WiFi
.
macAddress
());
...
...
libraries/ESP_NOW/src/ESP32_NOW.h
View file @
78820f22
...
...
@@ -41,9 +41,12 @@ public:
//optional callbacks to be implemented by the upper class
virtual
void
onReceive
(
const
uint8_t
*
data
,
size_t
len
,
bool
broadcast
)
{
log_i
(
"Received %d bytes from "
MACSTR
" %s"
,
len
,
MAC2STR
(
mac
),
broadcast
?
"broadcast"
:
""
);
log_i
(
"Received %d bytes from "
MACSTR
" %s"
,
len
,
MAC2STR
(
mac
),
broadcast
?
"(broadcast)"
:
""
);
}
virtual
void
onSent
(
bool
success
)
{
log_i
(
"Message transmission to peer "
MACSTR
" %s"
,
MAC2STR
(
mac
),
success
?
"successful"
:
"failed"
);
}
virtual
void
onSent
(
bool
success
)
{
log_i
(
"Message reported as sent %s"
,
success
?
"successfully"
:
"unsuccessfully"
);
}
};
class
ESP_NOW_Class
:
public
Print
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment