I already created a GitHub issue, but posting here for visibility and discussion.
Listening mode on the photon requires 70% of the user available RAM on the photon if threading is enabled.
This means that if the user application uses more than 13kB of RAM, the device will be out of memory when listening mode is triggered. This causes lockups, WiFi not restarting, or hard faults.
Now you might think, what if I use System.on(setup_begin) to try to free all my memory before listening mode runs? Nope.
The SoftAP application is constructed before that hook is called.
So the only way to make listening mode work at the moment, is to have the application memory use under 13kb at all times.
See more details in this GitHub issue:
- Don’t include the HTTP server on the photon. I have no idea why it is default included on the photon, but not on other platforms. This saves a lot of RAM
- Check available memory on SoftAP start. If free RAM is really low, only start Serial. Add more services if there is room.
- Give the user control over which services are included.
Anyway, the current implementation is horribly broken, but most users won’t notice. This is because:
- They have a very small app not using much RAM
- They hit a memory limit, but the symptoms are vague. Hard fault on out of memory is not enabled by default (which is good). But that means that all kinds of other things stop working randomly instead of a hard crash.
Would it be possible to have my own version of SoftAP triggered on button hold? So I can exclude mode of the services myself? I’d rather see a fix from Particle to save myself the work, but if it takes too long I will have to find a workaround.
Alternatively, can I completely disable listening mode in the user app? I have other ways to configure WiFi over Serial. No listening mode is better than a crash on demand button.
Is safe mode a viable alternative? Can I jump to safe mode instead when listening mode is triggered?