WiFi.scan() callback in a class crash

I’m trying to make a class based on the class template that @rickkas7 shared in this topic: Photon wi-fi signal strength indicator LED

I’d like to use the WiFi.scan callback function in a class. I tried different things but my C knowledge is probably not sufficient.

First attempt which doesn’t compile.

Other attempt based on the find Strongest WiFi class example from the documentation.
This compiles but gives me a red SOS message with 1 blink (Hard fault):
https://docs.particle.io/reference/firmware/photon/#scan-

The first one won’t work because only some of the Particle callback function handlers can accept a non-static member function as the callback. You can tell because they take a this pointer as an argument as well as the method.

WiFi.scan() is one that doesn’t. But the technique used in the second bit of code, a static member function that takes the this parameter in the data field, is the way to work around it.

I didn’t see anything obviously wrong with the second code sample, though I didn’t look that closely. And actually it worked without crashing for me.

I’ve found that the crash happens when threading is enabled SYSTEM_THREAD(ENABLED);

I’ve put the code in one file and clean it up a bit:

Adding a delay of 800 microseconds to the end of the setup() function solves the crash. Any idea why?

The same happens with the example from the documentation. In my test Photon there is one credential stored with a wrong password (by purpose), so it keeps connecting.

Hello @kasper That seems like a bug! Can you create a github issue for your observations please?

Thanks!

I’ve filed an issue:

1 Like