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

by MrDIYLab in Circuits > Wireless

3303 Views, 5 Favorites, 0 Comments

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

Thumbnail.png

Let's dig a bit deeper into ESPNow and explore unicast, broadcast and how they affect acknowledgements and retransmissions.

Watch the Video

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

ESPNow

unicastvsbroadcast.png

If you are not familiar with ESPNow. It is a protocol developed by espressif that allows multiple devices to communicate directly using the 2.4Ghz frequency without the need for a  Wi-Fi stack. It is a peer-to-peer communications and If you ever used a wireless mouse or keyboard with a  2.4Ghz dongle, it is pretty much the same concept.

And a refresher, unicast is when a message is sent to one and only one recipient. Broadcast is when a message is sent out to anyone who is listening.

Acknowledgments

acks.png

To put things in perspective, let's see how an ESPNow communication stream looks like. I setup Wireshark on my computer to capture all the wireless packages around me and added a filter for ESPNow using the mac address of the sender and receiver.

 

For this setup, I have a wemos d1 mini acting as an ESPNow sender and is sending out a package very 1 second to a second wemos d1 mini. By capturing the stream, we can see each package that is sent out is acknowledged right away by the sender.

 

This is however not the case with broadcast. In broadcast mode, packages are not acknowledged. And that is the first difference. Unicast is acknowledged and thus a bit more robust. Broadcast is not but is slightly faster because it doesn't' need to wait for acknowledgement.

 

So that means, in the code, in unicast, status=1 means it was SENT and RECEIVED successfully by the receiver. But in broadcast , status=1 means it was SENT successfully but without any receive confirmation.

Retransmissions

retransit.png

ESPNow has a built-in retry mechanism that is not very known. The catch: it only works in unicast. There are no retransmissions in broadcast.

 

Again here is a stream of ESPNow packages … and half way, I unplugged the receiver. ESPNow keeps resending the same package over and over. I counted 11 times in total. Then, it gives up and sets status=0 in the callback function.

 

I tried the same thing with broadcast with the receiver still unpowered. No retransmission, not once. Confirming broadcast packages are only sent out once.

PCBWay

Screen Shot 2021-10-24 at 10.58.25 PM.png

A shoutout to PCBWay for sponsoring this article. If you are a hobbyist and in the market for PCBs, I highly encourage you to give them a visit. Get 10 PCBs for $5 USD at https://www.pcbway.com

My Sensors

When I initially started using ESPNow, I heavily used broadcast in my sensors because it was easier and I didn’t need to know the mac address of my hub in advance. Then I switch to unicast to take advantage of the retries and acknowledgment. Now I see fewer missed packages especially when my sensors are placed at the edge of the ESPNow range.

I hope this has cleared or verified some of the ESPNow aspects for you. Thanks for reading!

If you found this useful, maybe consider visiting my YouTube channel and say hello. I will be posting future updates about this project.