Wifi reports one MAC, ESPNOW scan, finds different MAC, how can I find the right one?

I’m using ESP-NOW to send data to a “client”. Very small data packs. I have it working at the moment by using manually inserted MAC addresses (hard coded). So, I have the proper MAC addresses, it’s reported at boot, and when programming the device.
But, it would be nice if I could use the scanner in the Arduino ESP32/ESSPNOW examples, as the boards I use may change from time to time. (all this code does, is scan the network, looking for an SSID prefix, then reads the associated MAC address.
But when the scanner runs, it reports a very similar MAC address. Usually, off by one digit. How can I tell the scan code to to obtain the correct address?

This is the relevant code from the scan example:

if (SSID.indexOf("Slave") == 0) {
        // SSID of interest
        Serial.print(i + 1); Serial.print(": "); Serial.print(SSID); Serial.print(" ["); Serial.print(BSSIDstr); Serial.print("]"); Serial.print(" ("); Serial.print(RSSI); Serial.print(")"); Serial.println("");
        // Get BSSID => Mac Address of the Slave
        int mac[6];

        if ( 6 == sscanf(BSSIDstr.c_str(), "%x:%x:%x:%x:%x:%x",  &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5] ) ) {
          for (int ii = 0; ii < 6; ++ii ) {
            slaves[SlaveCnt].peer_addr[ii] = (uint8_t) mac[ii];
          }
        }
        slaves[SlaveCnt].channel = CHANNEL; // pick a channel
        slaves[SlaveCnt].encrypt = 0; // no encryption
        SlaveCnt++;

You can use ESP-NOW broadcast.
This will reduce the complexity (scan first, collect mac addresses, send data to selected addresses…) of your project a lot.

Take a look at the broadcast examples:

Note:
These examples requires Espressif Arduino 3.x.
You have to use pioarduino’s espressif32 platform!

Thanks! I downloaded that library before, but I thought the examples were the same.
It’ll take me a bit to look at it and test it (for my application).

But… do you think this will work in both master and slave? By that, I mean, can they both scan and find out what’s out there? So no addresses, in either master/slave are hard coded?

I “think” that was one problem with the other example, it was master/slave oriented, the master finds the slaves. But the slaves didn’t find the masters. And putting the “master scan” on the slave, caused other issues. (but I’m not positive on that, yet)

You don’t need to download the library as it is part of the Espressif Arduino Framework.
But you need version 3.x - so you have to use pioarduino (as written as before)

This is a broadcast example. Every ESP-NOW listener will receive the message you send.
I used this a lot a few months ago having one sender and many receivers.

I had downloaded it to look at it, I think I was switching a while back on another project.

I’m building a project that has one 7" display with integrated ESP32 (I may go bigger with two integrated esp32s). And several remote esp32s. So, everything needs to find everything else, as board may come and go, get changed out as I develop. Eventually, they’ll be hard to physically change out, so not hard coding addresses is important.

I’ve had so many problems with this. I started out with WiFi, and that couldn’t work, so I spent a lot of time on BLE (then NIMBle), but that got really complicated, really fast. So I’m back to WiFi again. It’s been a nightmare, I should have been mostly done months ago. The worst part is, the original WiFi would have worked. For some reason, I thought esp-now would not work with wIfi (which is hard requirement at this time). No idea why I thought that, but I did.

I’d like to use OTA updates. But I can’t seem to get that to work any longer. I had used it in other projects before, but now I can’t seem to get it work.

I noticed you post a lot, and very good information. You’re a prolific geniuses! Thanks for your help.

Well…

I finally got around to testing things out, and now everything is hammered.

I used the pioarduino extension. A pop up came up with an extension for a reset decoder, that is supposed to identiify why your esp32 resets itself. I thought that might be handy, so I installed that. (never saw it do anything though, so uninstalled it, it doesn’t seem to work with the boards like Waveshare Zero that don’t have a “hard serial port”)

And tried a new project with just the OTA example to see if I could get that working so I could add it to my project (as it would greatly simplify my life). At first, it wouldn’t do anything, it was rebooting as per the code. (reboot after about 5 seconds).

So I added a delay, and the wifi init code from my other project that worked. And then it just starts rebooting right off the get go.

Now even (last working) project I was working on last week, is doing the same. Everything just reboots on start up.

Took out platform = GitHub - pioarduino/platform-espressif32: Espressif 32: pioarduino community platform compatible with PlatformIO · GitHub
and “should” have go back to what I had, but nothing but reboots now.

Any ideas?

(I was working on a project involving a couple of boards, everything was working fine.
We went in the TV to a campground (which is why I couldn’t try out the code at first). I finally got a chance to try things out, and here I am. Nothing has changed except location, network is Starlink instead of t-Mobile at home).

You should only use pioarduino espressif32 platform, not the extension!

Remove the pioarduino extension, reinstall PlatformIO extension.
To revert back to PlatformIO’s espressif32 platform edit your platformio.ini and set the platform to the exact version you want to use:

platform = espressif32 @ 6.12.0

Here you’ll find a list of the available espressif32 platform versions (PlatformIO and pioarduino):slight_smile: GitHub - sivar2311/platform-espressif32-versions: A list of espressif32-platform versions for PlatformIO / pioarduino · GitHub

The reason I did that was, as I mentioned, I tried the OTA example, and it kept screaming about “Network.h” not found. So I figured it was in that zip, so I added that, and it compiled OK, but never got any further.

I’ll try again. I did get everything to revert. I need to get something, anything, to log on to the network first. For some reason, none of these esp boards will log on to starlink.

The reason I did that was, as I mentioned, I tried the OTA example, and it kept screaming about “Network.h” not found. So I figured it was in that zip, so I added that, and it compiled OK, but never got any further.

I’ll try again. I did get everything to revert. I need to get something, anything, to log on to the network first. For some reason, none of these esp boards will log on to starlink.

if/when I go back to pioarduino, no changes have to be made to the files in the older projects eh?

Sorry, I don’t understand a word.

You do not need to deal with any ZIP files.
What Problem do you have with OTA?
What do you mean with “connect to Starlink” ? Afaik the ESP32 cannot connecect to satelites directly.

Too many things at once.

I don’t know your programming skill.
Do you know https://randomnerdtutorials.com ?

Make small seperated test projects for each of your problem.
Solve them one by one, not all at once.

Unfortunately the topic about Espressif Arduino 2.x and 3.x is a bit complicated when it comes to PlatformIO. If you want to use the latest available Espressif32 Arduino 3.x you have to use pioarduino (just the platform, not the plugin!) e.g.

platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.38-1/platform-espressif32.zip

If you want to stick with the (outdated) Espressif32 Platform 2.x (supported by PlatformIO) use

platform = espressif32 @ 6.12.0

I apologize for the mis-understanding, yes, I have way too many things going at once. All too often, it’s one step forward, two steps back…

I have been doing each part (OTA, ESP-NOW) as their own test program, and then when something is working, I add another piece of the puzzle to it. But at times, I have to backtrack, and get what was working, remove something and get something else working in it’s place (like I had to remove all the BLE stuff, and switch back to ESP-NOW)
And I do know about Random Nerds and use them a lot to get started, but some of their examples are getting a bit dated. That’s where I had OTA working a while back, but somewhere down the line, something changed and the code I had, no longer worked. So I had to used an updated library and get that working.

So, yes, I got OTA working. One issue was a boneheaded mistake on my part. I set the network up with a “NAME_NUMBER” scheme. But, when I setup the network, I had inadvertently used an extra underscore. Very hard to see! Another issue was Firewall, the blocking python.

So far, everything is working as it should be.

Now that OTA is working, I’ll integrate the ESP-NOW, and the WiFi sections, and then add all the (working) LVGL stuff back in.

Again, sorry for the confusion, and again, thanks for your help.
(not that it matters, but my skill level is mostly hardware. I’ve worked in R&D most of my adult life. I do enjoy programing, but prototypes are my area. Certainly no expert in C)

1 Like

One of the issues with ESP-NOW is that it changed significantly in Espressif Arduino 3.0 and the RandomNerdTuorials examples are based on the older Esspressif Arduino 2.0, as are a lot of other examples on the net. I would urge you to listen to sivar2311 and use the pioarduino platform otherwise you are building problems into to your project. Another thing to be mindful of is that some ESP32 devices have different MAC’s for STA and AP mode, that is possibly why you see different MAC’s. When I use ESP_NOW I use broadcast mode and I make sure the transmitted messages have a unique identifier for the intended recipient device. The receiving device simply checks if the message content is for it.

I can still use them, but only as a rough idea of what they’re doing. As long as I know the code is older and has to be greatly modified, I’m good with 'em. They’re still helpful.

Oh I value everything he says. I’m currently running pioarduino. I just started looking closely at the example for ESP_NOW, hopefully, I’ll be able to get that running in the next couple of days (when time allows). (we’re camping in an RV for the next couple of months, so time is a bit scarce)

Ok, if the ESP is using a different address, how do you find it? I know it’s an older example code, but I’d still like to know in case I run into this later. In my older code, they would never communicate, because the scanner found one address, but the sender used a different address to actually send the message. Do you know how I could tell it look for the other address?

Thanks for your insight.

sorry for the late reply, I’ve been away for some days. I am not 100% sure I understand what you mean. ESP devices usually have the MAC address ‘burnt in’ they may be different for the STA and AP modes. Lately, my newer ESP devices do not show an AP address, maybe the command has changed. These two lines should get you those address’s for you.
Serial << (F("\n STA MAC Address: ")) << (WiFi.macAddress()) << ‘\n’;

Serial << (F(" AP MAC Address: ")) << (WiFi.softAPmacAddress()) << ‘\n’;
In my ESP-Now projects I either used the STA MAC address for a single device or broadcast mode to all devices.
There are some code examples in the Arduino IDE for ESP-Now I suggest you try those too.