I found other problem of SYSTEM_THREAD(ENABLED).
I use local build (using GCC-ARM), but if I use SYSTEM_THREAD(ENABLED) with Serial.read, then it will break the ability to flash the device with serial command.
If you flash that code with the following terminal commands, then it works and can be uploaded a new firmware:
cd /Users/atom/Documents/Particle/src/firmware/main
make all PLATFORM=photon APPDIR=/Users/atom/Documents/Particle/src/test
particle flash --serial /Users/atom/Documents/Particle/src/test/target/test.bin
But if you uncomment the SYSTEM_THREAD(ENABLED); and flash the code then it works the first flash, but after that you are not able to flash one more time… Only by other method like web build.
Is there a way to detect, that I am listening mode? Then I can disable in my code to read serial communication??
Also that would be nice to have some list in docs, what SYSTEM_THREAD(ENABLED) will break…
Just surround your serial reading code with a check for WiFi.listening() or Cellular.listening().
In system thread enabled your code runs when in listening mode. If you read the serial port while in listening mode, you’ll interfere with the ability for code flashing in --serial mode, as you’ll read the bytes instead of listening mode. Sending data will also cause problems. You may just want to return from loop() when in listening mode.
Or just use --usb and DFU (blinking yellow), which is more reliable anyway.
"You may just want to return from loop() when in listening mode."
How can I do that? Do you have a code for me please?
"Or just use --usb and DFU (blinking yellow), which is more reliable anyway."
I would be happy with it, but is it a simple way to get the photon in DFU mode besides pushing the buttons all the time? I used the serial version only because it does not require to push anything.