ESPNow, a Deeper Look: Unicast vs Broadcast (ACKs & Retries)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

In this video, I explore ESPNow a little deeper by looking at unicast, broadcast and how they affect acknowledgements and retransmissions.

👍︎︎ 3 👤︎︎ u/letmetryallthat 📅︎︎ Oct 25 2021 🗫︎ replies

That's an amazing feature for ESP microcontrollers, that helps a lot to auto descover new devices and even the first step configuration for a new device.

👍︎︎ 1 👤︎︎ u/judlup 📅︎︎ Oct 25 2021 🗫︎ replies
Captions
let's dive into esp now more specifically into the difference between unicast and broadcast and how they affect package retransmissions and acknowledgements [Music] if you are not familiar with esp now it's a protocol developed by espressif that allows multiple devices to communicate directly using the 2.4 gigahertz frequency without the need for a wi-fi stack it's a peer-to-peer communication and if you ever use a wireless mouse or a keyboard with a 2.4 gigahertz dongle it's pretty much the same concept first let's start with how the code is structured to send esp now messages it is actually very simple all we need to know in advance is the mac address of the device that we want to send a message to the code looks something like this after including the libraries we record the mac address of the receiver then the device declares itself as a sender then a message is sent out with the esp now send function but as you can see we need to know in advance the mac address of the receiver luckily there is another way to send messages out it is called broadcast and as you have guested it is asking everyone to listen on the message so any espno receiver out there will get the message but there is a small catch which is not very well documented and it has to do with re-transmissions and acknowledgements in the code when you are setting up esp now you can specify a callback when the message is successful it looks something like this this callback function passes a status variable when the value of the status is 1 it indicates success and when it's 0 it indicates failure this is very straightforward but what is not obvious at first is when status equals 1 has a different meaning depending if you are using unicast or broadcast and a refresher unicast is when a message is sent to one and only one receiver broadcast is when a message is sent out to anyone who's listening to put things in perspective let's see how an esp now communication stream looks like i set up wireshark on my computer to capture all the wireless packages around me and i added a filter for espnow using the mac address of the sender and receiver for this setup i have a wemas d1 mini acting as an esp now sender and it's sending out a package every one second to a second wemas d1 mini by capturing the stream we can see that each message that is sent out is acknowledged right away this is however not the case with broadcast in broadcast mode packages are not acknowledged and that's the first difference unicast is acknowledged and thus a bit more robust broadcast is not but it's slightly faster because it doesn't need to wait for an acknowledgement so that means in the code in unicast when status equals 1 means it was sent and received successfully by the receiver but in broadcast status equals 1 means it was sent successfully but without any receive confirmation another difference is re-transmissions esp now has a built-in retry mechanism that is not very well known but the catch is it only works in unicast there are no retransmissions in broadcast again here is a stream of esp now packages and halfway i unplugged the receiver esp now keeps resending the same message over and over i count it 11 times in total then it gives up and set the status equals 0 in the callback function i tried the same thing with broadcast with the receiver still empowered no retransmissions not once confirming that broadcast packages are only sent out once one thing is still puzzling me though is this here i have an esp now node sending broadcast packages but i don't have any other esp now nodes powered on but yet i am seeing acknowledgments in wireshark let me know down in the comment section if you have an explanation for this when i initially started using esp now i heavily use broadcast in my sensors because it was easier and i didn't need to know the mac address of my hub in advance the hub was my receiver then i switched to unicast to take advantage of the retries and acknowledgments now i see fewer missed packages especially when my sensors are placed at the edge of the esp now range so this was a quick overview of the esp now acknowledgments and retransmissions i hope this has cleared or verified some of the esp now aspects for you feel free to share some of your own down in the comment section i would love to hear them thank you for watching
Info
Channel: MrDIY
Views: 881
Rating: undefined out of 5
Keywords: DIY, MrDIY, ESPNow, Unicast, Broadcast, acknowledgement, retransmission, espnow asks, espnow retransmission, espnow callback, espnow send status, espresso espnow, espnow acknowledgment, Peer to peer
Id: Xmzk6v5qIjo
Channel Id: undefined
Length: 5min 20sec (320 seconds)
Published: Sun Oct 24 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.