Just some general hints for what I’ve seen so far.
- for switches you should use
INPUT_PULLDOWN
orINPUT_PULLUP
unless you’ve got external pull resistors. -
WiFi.selectAntenna()
is only needed once when switching between antenna types, not each time - give
SYSTEM_THREAD(ENABLED)
a try (and/or play withSYSTEM_MODE(SEMI_AUTOMATIC)
) - if you call
Particle.publish()
without connection (even before signalled via LED) you might cause issues, try to checkParticle.connected()
first (should cured in 0.5.0) - don’t quite give up yet, firmware 0.5.0 is not too far away and will improve stability (e.g. publish issue)
- minor style issue: Use
Particle.
instead of deprecatedSpark.
- make sure your publishes don’t violate the 1/sec (with 4/sec burst + 4sec pause) rate limit
- break up multi instruction lines - makes it easier to read and understand
Non of this alone will cure your issue, but might help stability.
I just reformatted your code by wrapping it between
```cpp
// your code
For more hints have a look here
https://community.particle.io/t/forum-tips-and-tricks/3999