Cloud disconnects when multiple Mode button presses encountered with photon 2

I was adding code to a photon 2 project and noticed it did not like 2 or more Mode button presses. One press would work ok. Once in a while 2 clicks might work without disconnecting from cloud. Also, when the Mode button is pressed once the Cyan LED changes to dim Green then flashes Green 4 or 5 times then returns to breathing Cyan. For multiple clicks, the LED goes dim white then dark. Cloud is disconnected and I need to reboot device.

This code below works ok for Argon but does not for Photon 2 when multiple button presses occur. Is there something I am doing wrong? Thanks for your help. :slightly_smiling_face:

//  Device Argon  &   Photon 2
//  Device OS 5.4.0

#include "Particle.h"

SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(SEMI_AUTOMATIC);

SerialLogHandler logHandler;

bool buttonPressed = false;
int buttonClicks = 0;
char eventData[64];

void buttonHandler(system_event_t event, int data) {
    buttonPressed = true;
    buttonClicks = system_button_clicks(data);
}

void setup() 
{
    System.on(button_final_click, buttonHandler);//  https://docs.particle.io/reference/device-os/firmware/#system-events
    Particle.connect();//comment out this line for testing, too
}

void loop() 
{
    if (buttonPressed) {
        buttonPressed = false;
        Log.info("button pressed %d time(s)", buttonClicks);

        if (Particle.connected()) {
            snprintf(eventData, sizeof(eventData), "number of times: %d", buttonClicks);
            Particle.publish("button_pressed", eventData);
        }
    }
}

Tapping the MODE button twice on the P2 and Photon 2 cause soft power off, like the Electron. I'm not sure why it does that, but it does and goes into HIBERNATE sleep mode and you need to reset the device or remove power to get out of it.

One MODE button tap is the signal strength indicator. Cellular devices do that, but Wi-Fi devices like the Argon did not, but now the P2 and Photon 2 also show RSSI on one MODE button tap like cellular devices.

1 Like

Ok. Thank you!

Hey, interesting fact, where do they show up, the serial console?
Thanks

1 Like

It's actually bars, the more blinks the more bars, but it's calculated from the RSSI.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.