Master ESP-NOW: Easy ESP32 Broadcast & P2P Communication Explained

  Переглядів 28,104

atomic14

atomic14

День тому

In this video, we learn how to broadcast a message from one ESP32 to multiple ESP32 and then we learn how to send a message from an ESP32 to a particular ESP32.
All of this without a WiFi router or base station. Instead, we will use ESP-NOW.
www.espressif.com/en/products...
"ESP-NOW enables a direct and low-power control of smart lights, without the need of a router. This method is power-efficient and convenient."
You can find the GitHub repo with the sample code here: github.com/atomic14/ESPNowSim...
Music: www.bensound.com/royalty-free...
---
Want to help support the channel? I'm accepting coffee on ko-fi.com/atomic14

КОМЕНТАРІ: 104
@atomic14
@atomic14 2 роки тому
Interested in ESP32 Audio: ukposts.info/slow/PL5vDt5AALlRfGVUv2x7riDMIOX34udtKD Looking for all my ESP32 projects: ukposts.info/slow/PL5vDt5AALlRdN2KyL30l8j7kLCxhDUrNw
@originuk
@originuk 2 роки тому
Thanks for taking the time out to show your experiment, workings and results :-) I love how you balance a journey from nothing to context to straight-to-the-point... makes it easy to skip over what I thought I knew, then realise you know more than me, becasue I can go back and listen more carefully. Cheers!
@atomic14
@atomic14 2 роки тому
Thanks, was fun making it, though I did get slightly bored walking up and down after a while...
@mikewa9097
@mikewa9097 3 роки тому
Easy and concise examples and Demo of the ESP Now functionality. Cheers!!!
@atomic14
@atomic14 3 роки тому
Thank you!
@sprucescience
@sprucescience 3 роки тому
Thank you for sharing! Great job!
@atomic14
@atomic14 3 роки тому
Thanks for watching!
@EngineeringNS
@EngineeringNS 2 роки тому
Amazing video, first one on ESPnow that went though the code like this instead of saying "Okay now copy and paste this code".. Great video, Subbed
@JBoek30
@JBoek30 2 роки тому
Nice Thanks 4 showing this , its epic love to try it :D
@JonahNeff
@JonahNeff 3 роки тому
Thank you very much. I was (and still am) struggling to find proper documentation for this, but your example was extremely clear and lucid. Thanks!
@atomic14
@atomic14 3 роки тому
Thank you!
@paule6101
@paule6101 Рік тому
This is really helpful, thank you
@freeler9933
@freeler9933 2 роки тому
Great video, as always!
@atomic14
@atomic14 2 роки тому
Thanks! Much appreciated.
@Parahooners
@Parahooners 3 роки тому
Great video, thank you. I'd really like to see one explaining how to send data such as A0 pin or BMP280 to another display and have that display on a oled screen... Keep up the great work and thanks for the guide 👍
@atomic14
@atomic14 3 роки тому
Sounds like a good project - I'll add it to the llist
@okoman90
@okoman90 3 роки тому
good example thank you
@rodneytapit5636
@rodneytapit5636 2 роки тому
Thanks for clear to the point tutorial. I found the button doesn't always toggle the led in the 'other' ESP32 dev kit module, like about 1 out of 3 times it will miss even when modules a 4" appart, but serial monitor records success. I have heard that delay() func. can block ESPNow receive is this an issue or not in this case?
@YigalBZ
@YigalBZ 3 роки тому
Very clear and useful. Thank you. If I may, it could have been better if you had two ways communication, such as slave responds with data to the master.
@atomic14
@atomic14 3 роки тому
Thanks for the feedback, that's a very good point and definitely doable.
@steveburg5273
@steveburg5273 6 місяців тому
This was a fun video and I was able to make the changes as shown and flash a NodeMCU board as a slave. Out of curiosity I attempted the multi-master in the same way..... which lead to a giant rabbit hole! I was able to add lots of libraries until the wifi types started clashing with SDK libraries. I guess the 8266 implementation just isn't as good.
@JamesT65
@JamesT65 3 роки тому
Great example thanks
@yuxuanhuang3523
@yuxuanhuang3523 2 роки тому
Thanks for the explanation, I wonder how much bandwidth this method can have. Could you perhaps do an experiment in future videos?
@FrankGraffagnino
@FrankGraffagnino 3 роки тому
great stuff. i'm guessing that the device has to be awake when that register peer logic is called. can the code just dynamically try to register the peer before every message if it wasn't found at init?
@atomic14
@atomic14 3 роки тому
I don't see why not. I have a seen a few people implement automatic discovery as well. I need to do some investigation to really understand it though.
@YigalBZ
@YigalBZ 3 роки тому
Thanks for the good video. Comments: 1) ESPnow is working well for ESP32 as well. 2) Instead of sending strings you can send a package of variables (structure) , for example few integers. So easy to refer to a specific variable. 3) I am not sure I understand the protocol of one to many" if the MAC is FFFF*, so all ESPs in range get the message? I would think it is required to add the specific MAC addresses of the target devices.
@atomic14
@atomic14 3 роки тому
That's a very good point - I used strings as it was easier to understand in a simple demo, but sending structures is much better. For the broadcast, I believe that so long as the target devices have added the multicast address as a peer they will receive broadcast messages. So the device doing the sending doesn't need to know about the other devices.
@WistrelChianti
@WistrelChianti 2 роки тому
@@atomic14 when you sent to the multicast address, you commented that it triggers the callback for the sentMessage, but does it also trigger the callback for the receivedMessage on the device that is doing the sending? or is that only on the devices with the multicast as a peer that didn't actually send the message?
@atomic14
@atomic14 2 роки тому
@@WistrelChianti The device sending does not receive the message that it sent.
@rallymax2
@rallymax2 11 місяців тому
Thanks for sharing about esp now. I need this for my project and was looking at hardware change for Zigbee and now I don’t need to.
@charlesstatkus
@charlesstatkus 2 роки тому
Thank you.
@dhgray123
@dhgray123 3 роки тому
This has been a great video for helping me get started with ESP-NOW! Thanks for the terrific example! One question; I realize that ESP-NOW is using standard Wifi channels but how do you select the channel that will be used? I can't find any reference to a channel in you example so I assume it's defaulting to a specific one?
@atomic14
@atomic14 3 роки тому
Hi Don, that's a good question - it will default to use the channel that you configure the WiFi to be on. I think that by default this is channel 6 - but I could be wrong. You can set the channel using the WiFi.softAP.
@PuceBaboon
@PuceBaboon 2 роки тому
@@atomic14 You can also use "esp_wifi_set_channel(9, (wifi_second_chan_t) WIFI_SECOND_CHAN_NONE);", just before the call to disconnect (you'll need to "#include ", too). The "9" is the channel number. Actually displaying the channel number is a bit more difficult (because of that dangling, unused second channel).
@xyanxity8185
@xyanxity8185 2 роки тому
what program do you use in the video? thank's
@pjpmarques
@pjpmarques 3 роки тому
Nice explanation. By the way, what editor/IDE are you using?
@atomic14
@atomic14 3 роки тому
Thanks! I’m using VSCode with the PlatformIO plugin.
@hc1770
@hc1770 3 роки тому
Informative video. You can take a look at PJON, it abstracts the ESPNow making it easier to implement. It has this auto register feature which allows you to add nodes on the fly as well as encryption setup.
@atomic14
@atomic14 3 роки тому
That's really interesting - I've seen a lot of different attempts at auto discovery and most of them seem a bit half baked. PJON looks really nice and well tested. There's also Espressif's ESP-MESH which is similar to ESP-NOW but and has a built in mechanism for nodes to join networks.
@hc1770
@hc1770 3 роки тому
@@atomic14 I haven't tried ESP-MESH as it says it requires a router. My previous project I wanted to do without a router hence I went with ESP-NOW. But it seems interesting, I wonder far the ESP-MESH can get when the max number of layers is just 4.
@atomic14
@atomic14 3 роки тому
@@hc1770 I started looking into it, there's a lot of sample code to wrap your head around especially around getting out to the internet from nodes in the mesh. I'm not sure you need a router unless you want to access the outside world. There's also this github.com/espressif/esp-mdf which is another brunch of stuff to learn!
@hc1770
@hc1770 3 роки тому
@@atomic14 As I saw the diagram has the root node as the router, I suppose it's required. Will have to test it out to confirm. Interesting, it seems like there are quite a number of protocols out there. The ESP-MDF looks really promising!
@aleksandarzivkovic1792
@aleksandarzivkovic1792 3 роки тому
Great video. I've got it all working but can not work out how to send just an (int). Please can you help.
@atomic14
@atomic14 3 роки тому
You can send any data you want, just pass the address of the thing you want to send and the length. Something like this to send: int32_t value = 123; esp_now_send(broadcastAddress, (const uint8_t *) &value, sizeof(int32_t)); And this to receive: void receiveCallback(const uint8_t *macAddr, const uint8_t *data, int dataLen) { if(dataLen == sizeof(int32_t)) { int *value = (int *) data; Serial.printf("The value is %d ", *value); }
@aleksandarzivkovic1792
@aleksandarzivkovic1792 3 роки тому
@@atomic14 That was most helpful. Thank you very much.
@JNET_Reloaded
@JNET_Reloaded 2 роки тому
How can 1 use the ESP 32 board and a rf radio pair to communicate with other station with same setup? via serial console when connecting to a pc? can you make a tut on this?
@blacklion79
@blacklion79 3 роки тому
Interesting, could be such packages received/sended by non-EPS32 devices, for example, by normal Linux PC with "normal" WiFi card?
@atomic14
@atomic14 3 роки тому
It certainly looks possible - iot.stackexchange.com/questions/2345/802-11-action-frames-send-and-receive-in-software. However, I think you might get an easier solution using an ESP32 as a gateway device to send messages to other ESP32 via ESP-NOW. Looks like there is some effort going on here as well - hackaday.io/project/161896-linux-espnow
@fungsidney6175
@fungsidney6175 2 роки тому
Great!
@dasiths
@dasiths Рік тому
This is using an variant of wifi broadcast for broadcasting right?
@NormRasmussen
@NormRasmussen 3 роки тому
You have no idea how helpful your video was! Despite digging through so many libraries and reddit posts, your video helped clarify so many missing pieces. I have a comment and a question: I hope this comment helps others, but my experience in using and ESP8266 was the eep-now.h library does not work with esp8266 boards. The arduino IDE would only NOT throw an error when was chosen as the library. If you then read through that library on GitHub, you'll notice the espnow lib has far fewer options. I don't know if there is a workaround, but it seems the more roboust esp-now lib is only compatible with esp-32 boards. My question is: I like how this is one file for both boards. However, if I had a button on pin 4 and an LED on pin 4, how could I differentiate between them in the code? My pseudo-code in my head has me thinking adding to the if statement: if (macAddr = board1) && (digitalRead(button1) == LOW) digitalWrite(led1) on board 2. But that's where my thought falls short. How could I nest an if statement to toggle the LED on another mac address? Thanks again for your help!
@atomic14
@atomic14 3 роки тому
Hi Norm, that's really useful to know. I don't have any ESP8266 boards so have only been able to go on the documentation - but it sounds like ESP-NOW is best on the ESP32. It's an interesting question - how to share the same code base across multiple boards. You can send a message to just one device so you could have several buttons and hard code the destination for each button. You can send a message directly to another device by using its MAC address instead of the broadcast address. Not sure if that helps with your use case? if (digitalRead(button1) == LOW) { sendMessage(device1_mac, ....) } if (digitalRead(button2) == LOW) { sendMessage(device2_mac, ....) } etc...
@ticktock1157
@ticktock1157 3 роки тому
If I am interested in repeating what you did, what will I need to purchase and DL?
@atomic14
@atomic14 3 роки тому
You’ll need a couple of esp32 dev boards. On the software side you can use the Arduino IDE to program them. The code in the video is on GitHub. Good luck!
@markday3145
@markday3145 3 роки тому
Since it doesn’t have to associate with a WiFi access point, it should be much faster to send a message for a device that mostly sleeps, wakes up, and sends out some data before going back to sleep.
@WistrelChianti
@WistrelChianti 2 роки тому
I'm guessing you can't do ESPNOW and wifi (in AP or STA mode) at the same time? So if you wanted to create a system where 2 boards were to detect each other, you'd need them to time slice between wifi and and ESPNOW both "pinging" the broadcast address to alert any other ESPNOW devices of their presence/identity?
@atomic14
@atomic14 2 роки тому
You can have both running at the same time, you just need to make sure you use the same channel for both ESP-NOW and the WiFi.
@sndominic405
@sndominic405 5 місяців тому
Can you post Arduino code instead of platformio?
@JNET_Reloaded
@JNET_Reloaded 2 роки тому
how can we put a basic keyboard on this chip please?
@FPChris
@FPChris 3 роки тому
I need to have 4-6 ESP32 Cams. I need to tell them all to 'get frame buffer' then one by one send their frame buffers wirelessly to a pc. ESP Now seems like a good choice for the communication part but what method would be best for sending all the frame buffers? Framerate doesn't matter. I just need the data but obviously the quicker the better.
@atomic14
@atomic14 3 роки тому
I would think about running a small web server on your PC and have the ESP cameras push up their frames to the server using HTTP. I think ESP-Now could be good for the triggering - though I'm not sure what the latency is and how synchronised all the devices would be. Depending on your requirements you could pull the images from the Cams and have the PC coordinate things. Really depends on how close together the photos need to be taken.
@FPChris
@FPChris 3 роки тому
@@atomic14 thanks. I just tested this idea with a laptop and two cams on a node.js server through a small $20 travel router. It works but I think the esp32’s are the bottle neck. Fair amount of lag.
@atomic14
@atomic14 3 роки тому
@@FPChris I have found the ESP-CAM WiFi to be particularly bad. I've never been able to work out if it's my board or a common problem. You can try connecting an external antenna - didn't seem to have any impact on my device, but I have seen people saying it improves things.
@mikewa9097
@mikewa9097 3 роки тому
Just wondering, does ESP Now work between the ESP32 and ESP8266 modules?
@atomic14
@atomic14 3 роки тому
I believe it does yes.
@guywhoknows
@guywhoknows 3 роки тому
I found them easy to set up. But the info on rate and bytes is not equal... For ESP now, it's 250 byte (14 word) I believe it's UDP transfer? But docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_now.html Says it's slightly different. And I also hear.the max rate was 2mb. I ran a 'quick test on range' and found they were pretty good, local low power was on par with 2.4ghz WiFi.. as in a normal AP.
@atomic14
@atomic14 3 роки тому
It's some kind of proprietary protocol, but it does seem very similar to UDP.
@SmodoStein
@SmodoStein 3 роки тому
Is ESP-NOW only available on ESP32 or on any ESP8266 Devices ?
@atomic14
@atomic14 3 роки тому
Should work on both devices.
@electricalcoder3025
@electricalcoder3025 2 роки тому
when i tried practical communication of two esp boards using espnow i get only 15-20metre maximum range not a completely open area ,almost 2-3 walls were there between the two boards. I still dont understand how people claim to have range of above 200metres oin blogs and videos .Do you experience the same atomic 14?
@atomic14
@atomic14 2 роки тому
I'm afraid I'm one of those people :) (ukposts.info/have/v-deo/p6phlW2MqW2fzKM.html) but I was testing outdoors. Indoors walls really kill the range - we have quite an open plan house so get quite good indoor coverage (and our walls are only plasterboard, so don't block much of the signal). You could try the long range mode and see if that makes any difference in your case.
@electricalcoder3025
@electricalcoder3025 2 роки тому
@@atomic14 ok thank you
@huyyi2811
@huyyi2811 Рік тому
Can you show me the display codes ? Thank you !
@jrdevelopment2714
@jrdevelopment2714 3 роки тому
i cant believe that someoone is using vscode with the arduino ide theme. crazy people from the the internet! anyway, nice video.
@atomic14
@atomic14 3 роки тому
Haha - good spot - that wasn't deliberate, but now you've pointed it out I can't unsee it.
@EngineeringNS
@EngineeringNS 2 роки тому
Could you not use this to make an auto discovery? Have the master broadcast its mac, then all the peers respond with their MAC's and it would then save those and use them in later instead of broadcasting.
@atomic14
@atomic14 2 роки тому
Definitely possible - I've seen a few projects that do that.
@nvn93
@nvn93 2 роки тому
where to download esp_now library
@stark9397
@stark9397 2 роки тому
Please come ESP32 SIM800L videos master :)
@danieltrivino2935
@danieltrivino2935 3 роки тому
Thanks for sharing, Do you happen to know how to do it using Micropython? Thanks in advance for your help Daniel
@atomic14
@atomic14 3 роки тому
Looks like some work is being done - github.com/micropython/micropython/pull/4115
@danieltrivino2935
@danieltrivino2935 3 роки тому
Many thanks 👍
@stevegroen8036
@stevegroen8036 3 роки тому
Does this code work equally well for the new ESP32-S2?
@atomic14
@atomic14 3 роки тому
I don’t know for sure, but there’s no reason it shouldn’t.
@bruceb85
@bruceb85 3 роки тому
Are they hooked up to a usb hub?
@atomic14
@atomic14 3 роки тому
They are, but just for power. On my Walkie-Talkie project I've got it all battery-powered and working with ESP-NOW
@atomic14
@atomic14 3 роки тому
I think I also had some of them connected to power banks.
@Time4yes
@Time4yes Рік тому
Does a distance matter?
@atomic14
@atomic14 Рік тому
I did some tests here: ukposts.info/have/v-deo/p6phlW2MqW2fzKM.html
@JUSTICESKNYARKOJTC
@JUSTICESKNYARKOJTC 3 роки тому
1000 LIKES
@gmag11
@gmag11 3 роки тому
Great video, thanks. I'n my recen investigation I've found that ESP8266 stops receiving broadcast esp-now messages if you do a WiFi network scan. github.com/espressif/ESP8266_NONOS_SDK/issues/334 May you confirm that in your setup?
@atomic14
@atomic14 3 роки тому
I think if you want to use WiFi at the same time as ESP-NOW then you have to be a bit careful. You need to use the same channel for both the WiFi connection and the ESP-NOW connection. I think putting the device into scanning mode will cause issues as it probably completely takes over the WiFi connection and stops ESP-NOW from working.
@gmag11
@gmag11 3 роки тому
@@atomic14 I found a workaround. Check it on issue I linked on my message. ESP-NOW rules! Thank you. If you want to check my project have a look here github.com/gmag11/EnigmaIOT. I think it can be useful. Regards
@atomic14
@atomic14 3 роки тому
@@gmag11 That is an amazingly well-documented project and well worth checking out!
@GeorgeOu
@GeorgeOu 2 роки тому
They're using 802.11 frames so I don't know why they imposed a 250 BYTE packet size. I don't see any reason they don't just adopt the normal 1500 BYTE packet.
@atomic14
@atomic14 2 роки тому
I have seen some people on the forums changing it to get much larger packet sizes. I'm not sure why they have the limitation either.
@GeorgeOu
@GeorgeOu 2 роки тому
@@atomic14 You're saying that you can bypass the 250-byte limit?
@mkr32
@mkr32 2 роки тому
nice good can i control more led and servo motor like this please share come i want to try thanks i am happy to subscribe your channel
@charlietame1892
@charlietame1892 2 роки тому
Why do you feel the need to annoy the hell out of people with totally irrelevant music?
@atomic14
@atomic14 2 роки тому
Check out some of the more recent videos - no music!
ESP-NOW - Peer to Peer ESP32 Network
43:02
DroneBot Workshop
Переглядів 323 тис.
ESPNOW mix with #ESP32 and #ESP8266
25:37
Programming Electronics Academy
Переглядів 32 тис.
BRAWLER MUTATIONS WILL BREAK THE GAME! - Brawl Talk
09:34
Brawl Stars
Переглядів 24 млн
FOOTBALL WITH PLAY BUTTONS ▶️ #roadto100million
00:24
Celine Dept
Переглядів 105 млн
ESPNOW to Internet Gateway 🌎
15:02
techiesms
Переглядів 17 тис.
ESP NOW: Espressif's Wireless-Communication Protocol
9:20
Espressif Systems
Переглядів 103 тис.
ESP-Now Range Test: Real-World Results for ESP32 Devices!
8:01
atomic14
Переглядів 101 тис.
Why ESPNow is awesome - hint: ACKs & Retries!
5:20
MrDIY
Переглядів 17 тис.
Why Did I Pick Wi-Fi over ESPNow?
4:53
MrDIY
Переглядів 16 тис.
ESP32-to-ESP32 Simplex Communication via ESP-NOW
6:31
Anas Kuzechie
Переглядів 47 тис.
Anyone Can Send Data to Anyone | ESPNOW Many To Many Communication
9:07
Phone sees the future ! 📲🫣👽
0:38
BOGDANCHIKI
Переглядів 11 млн
Это БЕСИТ ВСЕХ пользователей iPhone!!! 😡
28:07
Яблочный Маньяк
Переглядів 25 тис.