Skip to content

ESP8266 Custom MAC Failing After Power Oscillations #9137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
6 tasks done
fpalarminiscenario opened this issue May 13, 2024 · 3 comments
Closed
6 tasks done

ESP8266 Custom MAC Failing After Power Oscillations #9137

fpalarminiscenario opened this issue May 13, 2024 · 3 comments

Comments

@fpalarminiscenario
Copy link

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: ESP-12
  • Core Version: 2.7.4
  • Development Env: Platformio
  • Operating System: Linux Mint

Settings in IDE

  • Module: Generic ESP8266 Module
  • Flash Mode: qio
  • Flash Size: 4MB
  • lwip Variant: v2 Higher Bandwidth
  • Reset Method: nodemcu
  • Flash Frequency: 40Mhz
  • CPU Frequency: 80Mhz
  • Upload Using: OTA
  • Upload Speed: [115200|other] (serial upload only)

Problem Description

I have been setting a custom MAC address on the ESP8266 using the wifi_set_macaddr and wifi_get_macaddr functions. So far, it has been working as expected. I confirmed this by turning the device off and on again, and the new MAC address remained in effect.

Recently, I conducted a new test to simulate an oscillation in the power source by quickly unplugging and plugging it back in several times. During this test, I noticed an unusual behavior. After the power oscillations, the MAC address read by wifi_get_macaddr was reverted to its original value

To resolve this issue, I read the MAC address from the EEPROM and compared it to the value returned by wifi_get_macaddr. If they didn't match, I executed ESP.restart(), and the correct custom MAC address was restored.

I would like to understand why this issue occurs. Is there any code within user_init that could fail due to power oscillations? I appreciate any insights or suggestions to prevent this issue in the future.

Thank you

MCVE Sketch

#include <Arduino.h>
#include <EEPROM.h>

void loadMAC() {
    uint8_t mac[6];
    for(int i = 0; i < 6; i++)
    {
        mac[i] = EEPROM.read(i);
    }
    wifi_set_macaddr(STATION_IF, mac);
}

void verifyMAC() {
    uint8_t macESP[6];
    uint8_t macEEPROM[6];
    WiFi.macAddress(macESP);
    for(int i = 0;i < 6; i++)
    {
        macEEPROM[i] = EEPROM.read(i);
        if (macEEPROM[i] != macESP[i])
        {
            ESP.restart();
        }
    }
}

void setup() {
EEPROM.begin(100);
loadMAC();
verifyMAC();
}

void loop() {

}
@fpalarminiscenario fpalarminiscenario changed the title ESP8266 MAC Custom After Power Oscillations ESP8266 Custom MAC Failing After Power Oscillations May 13, 2024
@mcspr
Copy link
Collaborator

mcspr commented May 15, 2024

#8554 (comment) ?

STA interface needs to be up before changing its mac address

I don't see any mode change in your code, so you rely entirely on a chance SDK decides to bring IF up before setup(). This may not always be the case.

Unless the issue you are observing is with EEPROM erasing its contents?

@mcspr
Copy link
Collaborator

mcspr commented May 15, 2024

2.7.4

Also, please update to 3.1.2 w/ WiFi mode() call and retry

@fpalarminiscenario
Copy link
Author

#8554 (comment) ?

STA interface needs to be up before changing its mac address

I don't see any mode change in your code, so you rely entirely on a chance SDK decides to bring IF up before setup(). This may not always be the case.

You are right, it resolved my issue. I was setting mode after changing MAC address. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants