Particle.process() is required for listening mode even with SYS_THREAD(ENABLED)

PSA:

I have been struggling to get a semi-automated test stand working that writes a test firmware to the device, then runs a test procedure, then writes application firmware.

I am using particle serial flash to do this job, which relies on the P1 being in Listening mode. My test firmware starts out in listening mode and waits for a button press before starting the serial port, so that’s no problem-- that is, I can write firmware to it after any restart.

But what I found is that even with SYSTEM_THREAD(ENABLED), you MUST do a Particle.process() in your non-yielding code to make it work.

i.e. this works:

  WiFi.on();
  WiFi.setListenTimeout(0);
  WiFi.listen();

  bool ready = false;

  while(!ready) {
    //Serial.println("Waiting.. Press power button to start!");
    if (PAHardware.isPowerButtonPressed())  ready = true;
    delay(10);
    Particle.process();
  }

but this does not:

  WiFi.on();
  WiFi.setListenTimeout(0);
  WiFi.listen();

  bool ready = false;

 while(!ready) {
    // Print message once a second, test button every 1/10th
    //Serial.println("Waiting.. Press power button to start!");
    if (PAHardware.isPowerButtonPressed())  ready = true;
    delay(100);
    if (PAHardware.isPowerButtonPressed())  ready = true;
    delay(100);
    if (PAHardware.isPowerButtonPressed())  ready = true;
    delay(100);
    if (PAHardware.isPowerButtonPressed())  ready = true;
    delay(100);
    if (PAHardware.isPowerButtonPressed())  ready = true;
    delay(100);
    if (PAHardware.isPowerButtonPressed())  ready = true;
    delay(100);
    if (PAHardware.isPowerButtonPressed())  ready = true;
    delay(100);
    if (PAHardware.isPowerButtonPressed())  ready = true;
    delay(100);
    if (PAHardware.isPowerButtonPressed())  ready = true;
    delay(100);
    if (PAHardware.isPowerButtonPressed())  ready = true;
    delay(100);
  }

I had been under the impression that Particle.process() was a NOP in this system mode, and that seems not to be the case.

(Sorry for the weird messy code, but this was the precise change that made it work!)

Hi @HEng,
According to the documentation, Particle.process() does quite a lot?
https://docs.particle.io/reference/firmware/photon/#particle-process-

SYSTEM_THREAD just executes the code in a more decoupled manner. It doesn’t remove the requirement to call Particle.process() https://docs.particle.io/reference/firmware/photon/#system-thread

PS: Better not repost if nobody replies? It makes the forum messy.

1 Like