Skip to content
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

WiFi.macAddress() is 00:00:00:00:00:00 when using `SYSTEM_MODE(MANUAL)` #879

Closed
nneonneo opened this issue Feb 19, 2016 · 3 comments · Fixed by #954

Comments

@nneonneo
Copy link

commented Feb 19, 2016

When using SYSTEM_MODE(MANUAL), calling WiFi.macAddress() within setup or the first loop iteration results in an all-zeros MAC address being returned.

Test program:

#include "spark_wiring.h"
#include "application.h"

SYSTEM_MODE(MANUAL);

void setup() {
    WiFi.on();
    WiFi.connect();

    while(!WiFi.ready())
        ;
}

void loop() {
    byte mac[6];
    WiFi.macAddress(mac);
    Serial.printf("WiFi MAC address: %02x:%02x:%02x:%02x:%02x:%02x\n",
        mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
}

Invariably, the output from the first loop is WiFi MAC address: 00:00:00:00:00:00; the output is correct from the second loop onwards.

It can be fixed by using AUTOMATIC mode, but for our application this introduces a significant overhead which we don't need. We could also work around it by skipping the first loop but this seems like a bit of a hack.

Is there a function we can call from user (application) code that will refresh the MAC address, preferably callable from setup? Alternately, is there a way the firmware can be fixed so that the MAC address is always made available in MANUAL mode?

@nneonneo

This comment has been minimized.

Copy link
Author

commented Feb 19, 2016

Note: this was tested against the following firmware revision:

commit e4e4b975120353052c71a461fc0d194ab2d3633b
Author: Matthew McGowan <mat.mcgowan+github@gmail.com>
Date:   Tue Jan 26 03:20:08 2016 +0100

    updates changelog

which was compiled on my machine along with user code in user/applications.

@m-mcgowan

This comment has been minimized.

Copy link
Contributor

commented Feb 23, 2016

Thanks for the report. This stems from the way the system calls setup()/loop() and that setting the MAC address relies upon having the background loop executed.

The ideal fix is to have the system internally call Particle.process() between setup() and loop(). It presently doesn't do that, and runs setup() and loop() in succession, with no background processing in between. This has always been the case for firmware since very early on so any changes here we will need to thoroughly test.

Until then, as workaround you can call Particle.process() in setup after WiFi.ready() returns true, which will refresh the MAC address.

@m-mcgowan m-mcgowan assigned m-mcgowan and avtolstoy and unassigned m-mcgowan and avtolstoy Apr 8, 2016

@m-mcgowan

This comment has been minimized.

Copy link
Contributor

commented Apr 8, 2016

I think this is just a matter of fetching the ip config when wifi is first activated. I will code and test on Core/Photon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.