Problem with SYSTEM_THREAD and LISTEN_MODE

Hello, you are well ?

I’m using the Particle Electron to a project where I need control the time of Listen Mode. But, when I use SYSTEM_THREAD (ENABLE), I can’t debug my code in my electron. Obs: I’m using node.js and USB.

Thanks

My Code:

const int BT_LISTEN_MODE = D2;


void my_firmware_update(void);


SYSTEM_MODE(MANUAL)
//SYSTEM_THREAD(ENABLED)

void setup() {
    
    Serial.begin (9600);
    pinMode(BT_LISTEN_MODE, INPUT_PULLUP);
}

void loop() {
    
    my_firmware_update();
}
 
 void my_firmware_update(void){
    if(!digitalRead(BT_LISTEN_MODE)){
        Serial1.println("Preparado para atualizar firmware...");
        Cellular.on();
        Cellular.listen(!Cellular.listening());
    }
}

What will you be needing Listening Mode on the Electron for?
What exactly do you mean with this?

You might need to add a delay in your function in order to prevent one button press to trigger multiple triggers entering/leaving Listening Mode while holding down the button.

Hello ScruffR,

I’m creating a system where I will debug my firmware.bin with my Particle offline. When I use the command SYSTEM_MODE(MANUAL) and SYSTEM_THREAD(ENABLED), I’m not getting debug my electron.

At the command prompt the following message appears:

! serial:
Error writing firmware…Timed out waiting for initial response from device undefined

obs:
my electron is locked with the LED in blue.

I’ll have a look some time
But how are you debugging? Are you using a hardware debugging tool like Programmer Shield plus OpenOCD or just Serial.print()?
You may want to add some delay after entering listening mode in multi threaded mode to prevent multiple triggers with one button press.

e.g.

void my_firmware_update(void) {
  if(!digitalRead(BT_LISTEN_MODE)) {
    Serial1.println("Preparado para atualizar firmware...");
    Cellular.on();
    delay(100);
    Cellular.listen(!Cellular.listening());
    while(!digitalRead(BT_LISTEN_MODE)) Particle.process(); // wait for button release
  }
}

But I’m still not sure what you want with Listening Mode on an Electron :confused:

@pmjackson, you could use DFU mode to flash via particle flash --usb firmware.bin maybe thisworks better (providing you’ve got dfu-util installed too)