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

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 มิ.ย. 2024
  • 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 ปีที่แล้ว +1

    Interested in ESP32 Audio: th-cam.com/play/PL5vDt5AALlRfGVUv2x7riDMIOX34udtKD.html
    Looking for all my ESP32 projects: th-cam.com/play/PL5vDt5AALlRdN2KyL30l8j7kLCxhDUrNw.html

  • @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...

  • @sprucescience
    @sprucescience 3 ปีที่แล้ว +5

    Thank you for sharing! Great job!

    • @atomic14
      @atomic14  3 ปีที่แล้ว +2

      Thanks for watching!

  • @mikewa9097
    @mikewa9097 3 ปีที่แล้ว

    Easy and concise examples and Demo of the ESP Now functionality. Cheers!!!

    • @atomic14
      @atomic14  3 ปีที่แล้ว

      Thank you!

  • @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

  • @paule6101
    @paule6101 ปีที่แล้ว

    This is really helpful, thank you

  • @JonahNeff
    @JonahNeff 3 ปีที่แล้ว +2

    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!

  • @okoman90
    @okoman90 3 ปีที่แล้ว +1

    good example thank you

  • @steveburg5273
    @steveburg5273 7 หลายเดือนก่อน

    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.

  • @freeler9933
    @freeler9933 3 ปีที่แล้ว +1

    Great video, as always!

    • @atomic14
      @atomic14  3 ปีที่แล้ว

      Thanks! Much appreciated.

  • @JBoek30
    @JBoek30 2 ปีที่แล้ว +1

    Nice
    Thanks 4 showing this ,
    its epic love to try it :D

  • @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?

  • @Parahooners
    @Parahooners 3 ปีที่แล้ว +1

    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 ปีที่แล้ว +2

      Sounds like a good project - I'll add it to the llist

  • @JamesT65
    @JamesT65 3 ปีที่แล้ว

    Great example thanks

  • @charlesstatkus
    @charlesstatkus 2 ปีที่แล้ว

    Thank you.

  • @YigalBZ
    @YigalBZ 3 ปีที่แล้ว +2

    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 ปีที่แล้ว +1

      Thanks for the feedback, that's a very good point and definitely doable.

  • @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?

  • @rallymax2
    @rallymax2 ปีที่แล้ว

    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.

  • @dhgray123
    @dhgray123 3 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      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 ปีที่แล้ว +1

      @@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).

  • @pjpmarques
    @pjpmarques 4 ปีที่แล้ว

    Nice explanation. By the way, what editor/IDE are you using?

    • @atomic14
      @atomic14  4 ปีที่แล้ว +1

      Thanks! I’m using VSCode with the PlatformIO plugin.

  • @JNET_Reloaded
    @JNET_Reloaded 3 ปีที่แล้ว

    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?

  • @FrankGraffagnino
    @FrankGraffagnino 3 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      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.

  • @xyanxity8185
    @xyanxity8185 3 ปีที่แล้ว

    what program do you use in the video? thank's

  • @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!

  • @fungsidney6175
    @fungsidney6175 2 ปีที่แล้ว

    Great!

  • @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

  • @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...

  • @dasiths
    @dasiths 2 ปีที่แล้ว

    This is using an variant of wifi broadcast for broadcasting right?

  • @sndominic405
    @sndominic405 6 หลายเดือนก่อน

    Can you post Arduino code instead of platformio?

  • @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!

  • @aleksandarzivkovic1792
    @aleksandarzivkovic1792 3 ปีที่แล้ว +1

    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 we put a basic keyboard on this chip please?

  • @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.

  • @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.

  • @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 ปีที่แล้ว +1

      @@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.

  • @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 :) (th-cam.com/video/oz0a7Ur7nko/w-d-xo.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

  • @guywhoknows
    @guywhoknows 3 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      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.

  • @nvn93
    @nvn93 2 ปีที่แล้ว

    where to download esp_now library

  • @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 ปีที่แล้ว +1

      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.

  • @stevegroen8036
    @stevegroen8036 3 ปีที่แล้ว +1

    Does this code work equally well for the new ESP32-S2?

    • @atomic14
      @atomic14  3 ปีที่แล้ว +1

      I don’t know for sure, but there’s no reason it shouldn’t.

  • @stark9397
    @stark9397 3 ปีที่แล้ว

    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 ปีที่แล้ว +1

      Looks like some work is being done - github.com/micropython/micropython/pull/4115

    • @danieltrivino2935
      @danieltrivino2935 3 ปีที่แล้ว

      Many thanks 👍

  • @Time4yes
    @Time4yes ปีที่แล้ว

    Does a distance matter?

    • @atomic14
      @atomic14  ปีที่แล้ว

      I did some tests here: th-cam.com/video/oz0a7Ur7nko/w-d-xo.html

  • @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?

  • @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.

  • @JUSTICESKNYARKOJTC
    @JUSTICESKNYARKOJTC 3 ปีที่แล้ว +1

    1000 LIKES

  • @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

  • @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 ปีที่แล้ว +2

      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 ปีที่แล้ว +2

      @@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 ปีที่แล้ว +1

      @@gmag11 That is an amazingly well-documented project and well worth checking out!

  • @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!