As for now, I use hard coded MAC addresses of EWSP-NOW devices in my code, so every time a new device is added to the system, I need to recompile and burn few devices.
Is there a way to scan automatically all ESP-NOW devices in the nearest are, get from them a certain ID and MAC and configure them accordingly?
ESP-NOW: how to identify devices after boot?
-
- Posts: 9759
- Joined: Thu Nov 26, 2015 4:08 am
Re: ESP-NOW: how to identify devices after boot?
You can, but I'd do it the other way: the new devices can send an ESP-NOW packet to the broadcast MAC (ff:ff:ff:ff:ff:ff) and the receiver can receive those and try to configure the device.
Re: ESP-NOW: how to identify devices after boot?
How can I do that?
That is a nice idea, but it will fail in case the master device is going through a reset. After the master wakes up, the slaves will not re-send their ID., but I'd do it the other way: the new devices can send an ESP-NOW packet to the broadcast MAC (ff:ff:ff:ff:ff:ff) and the receiver can receive those and try to configure the device.
-
- Posts: 9759
- Joined: Thu Nov 26, 2015 4:08 am
Re: ESP-NOW: how to identify devices after boot?
Obviously you'd need to take care of that by e.g. going back into broadcast mode on having a timeout. Alternatively, have the master send a broadcast and have all devices react.
On the 'how': off the top of my head (but admittedly it's been a while since I used this), you just add the broadcast address as a peer and send/receive to/from there.
On the 'how': off the top of my head (but admittedly it's been a while since I used this), you just add the broadcast address as a peer and send/receive to/from there.
Re: ESP-NOW: how to identify devices after boot?
Can you share a code example of the master and slave for the case the master send "who is out there" and each slave respond?
-
- Posts: 9759
- Joined: Thu Nov 26, 2015 4:08 am
Re: ESP-NOW: how to identify devices after boot?
No, as I don't have one.
Re: ESP-NOW: how to identify devices after boot?
Sorry I don't have example code neither, but I do have code of a project that uses a similar functionality to configure and play an 'orchestra' of esp32 'instruments', so you might find a couple of hints grepping through the code. But be warned: the code is long quite complicated, chaotic, experimental, higly configurable. I wrote (and used) that code for live performances and electronic art installations and certainly *not* as an example of good programming techniques. It might confuse you more than helping you. You *have* been warned...
A few points for better understanding: there is no master, there are no slaves, just participants.
I can take any of the instruments and give instructions to configure and play the thing or send them (using esp-now) to other instruments. Each instrument has a simple morse input (using a touch input), or the input can be given through serial input or bluetooth.
Each instrument has a name (and some other parameters) stored in nvs as an ID. I do *not* set them by the program, but on very first use with one of the above mentioned input methods using a serial menu system, that let's me change a lot of settings at run time.
All my ESP-NOW messages include a code for it's meaning. So each instrument can broadcast a message to tell all the others to broadcast their IDENTITY (including the name). Depending configuration this can be sent after booting, after finishing to play music, on request through the morse interface, etc. On receiving an ID it will be stored in the peer-list of the other instruments.
After that this peers are known to them, can be addressed individually (i.e. to start playing or configuring them). The list can be displayed including name, mac etc of all the instruments.
Most instruments have some sort of small display (like ePaper or OLED).
As you might imagine the esp-now system is deeply burried in many other code files.
Grep for 'USE_ESP_NOW' which is the main configuration switch to use it.
Compilation starts with 'pulses.ino'
Basic ESP-NOW functionality is in 'esp_now_pulses.h'
I *did* tell you it is chaotic, didn't I?
https://github.com/reppr/pulses/
A few points for better understanding: there is no master, there are no slaves, just participants.
I can take any of the instruments and give instructions to configure and play the thing or send them (using esp-now) to other instruments. Each instrument has a simple morse input (using a touch input), or the input can be given through serial input or bluetooth.
Each instrument has a name (and some other parameters) stored in nvs as an ID. I do *not* set them by the program, but on very first use with one of the above mentioned input methods using a serial menu system, that let's me change a lot of settings at run time.
All my ESP-NOW messages include a code for it's meaning. So each instrument can broadcast a message to tell all the others to broadcast their IDENTITY (including the name). Depending configuration this can be sent after booting, after finishing to play music, on request through the morse interface, etc. On receiving an ID it will be stored in the peer-list of the other instruments.
After that this peers are known to them, can be addressed individually (i.e. to start playing or configuring them). The list can be displayed including name, mac etc of all the instruments.
Most instruments have some sort of small display (like ePaper or OLED).
As you might imagine the esp-now system is deeply burried in many other code files.
Grep for 'USE_ESP_NOW' which is the main configuration switch to use it.
Compilation starts with 'pulses.ino'
Basic ESP-NOW functionality is in 'esp_now_pulses.h'
I *did* tell you it is chaotic, didn't I?
https://github.com/reppr/pulses/
Last edited by OutOfLine on Mon Aug 22, 2022 4:16 pm, edited 1 time in total.
Re: ESP-NOW: how to identify devices after boot?
You certainly said it, very clearly....
I just don't know where is that chaotic code.
I just don't know where is that chaotic code.
Who is online
Users browsing this forum: No registered users and 60 guests