WiFi.listen() not working in combination with SPI?

hello,

in an application for the p1 i am using WiFi.listen() if there are no wifi credentials. it runs with SYSTEM_MODE(SEMI_AUTOMATIC) before and after the WiFi.listen() i use Log (and SerialLogHandler logHandler(LOG_LEVEL_ALL))

when the device is blinking blue (and unclaimed) and i use the particle app to “add” it works fine but i am missing some of the logging after the Wifi.listen()

although annoying, this is not the problem but might be a clue:

when i add code using the SPI interface (and A2 as select) i can no longer configure the device with the particle app: i get a “X” before “Configuring Wi-Fi credentials” followed by “Error! Setup process couldn’t configure the Wi-Fi credentials …” (and the blue led keeps blinking)

in case the P1 is already setup the code runs fine. anyone any idea?

thanks so much!
frank

ps:
browsing through the device-os code on github: why do i not see the log messages? like LOG(INFO, “Entering listening mode”);
how do i enable those? (i was hoping “LOG_LEVEL_ALL” whould do that)

You can try adding SYSTEM_THREAD(ENABLED) to ensure your application code is running while in LM.

I haven't looked into the implementaion of the LOG() macro in the device OS repo, but
these may be deactivated for release device OS and only do something when building with the debug flag.

adding SYSTEM_THREAD(ENABLED) makes it behave worse: after selecting the photon-xxx wifi and returning to the app it is stuck there…

okay, i narrowed it down to some weirdness:

this is part of my setup:

int need_upgrade = mm_needs_upgrade(version);

Log.info("need upgrade %d", (int)need_upgrade);

if(need_upgrade) {

    Log.info("upgrading mm");

    errorCode = mm_firmware_update(version);

    Log.info("upgrading finished with %d", errorCode);
}

if(!WiFi.hasCredentials()) {

        WiFi.listen();
}

this will cause the particle app to give an error right at “Configuring Wi-F- credentials”

now if i comment out the “if upgrade” it will work fine?? and this eventhough need_upgrade = 0! (see logging at the end)

so this works fine:

int need_upgrade = mm_needs_upgrade(version);

Log.info("need upgrade %d", (int)need_upgrade);

/*
if(need_upgrade) {

    Log.info("upgrading mm");

    errorCode = mm_firmware_update(version);

    Log.info("upgrading finished with %d", errorCode);
}
*/

if(!WiFi.hasCredentials()) {

        WiFi.listen();
}

anyone any idea?!!

oh and both work fine when wifi credentials are set

logging:
0000010151 [app] INFO: no credentials
0000010452 [app] INFO: current: 77
0000010453 [app] INFO: new: 77
0000010453 [app] INFO: need upgrade 0

okay, more detail: although the call to “mm_firmware_update” is not used it does cause the problem. my guess now is that linking in that call and associated code causes the problem with wifi.listen. it is code to flash a micro-controller over spi (and uses many times in other projects)

investigating further…

maybe turn the question around: what can cause wifi.listen to behave like this? (seems normal till you try to add the device with particle app)

any ideas very welcome!

i now belief it is a stack problem or something. a large array is used in the code that gets linked in there. when eliminate the use of that array it does work. will use a different/better implementation…

so i guess this question turns into a warning! weird behavior with wifi.listen --> check memory usage

For the sake of clarity - which device are you using (Photon or P1) and which device OS?

Are these your functions mm_needs_upgrade(version) and mm_firmware_update(version)?

From what you have shared it is unclear what you are using SPI for and what this need_upgrade is doing. You refer to an array but not where it is defined and used.

1 Like

i stated i was using a p1 in the original post… need_upgrade is just an int

especially in these weird situations it is not always possible to exactly state what all is doing

first i thought it was spi or serial, then maybe linked in code and turned out to be a memory issue

i think it is good to post these investigations as i am sure others encounter these as well

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.