Espurna: Relay turns on at boot.

Created on 24 Jul 2018  路  1Comment  路  Source: xoseperez/espurna

Hi,
I've noticed, that in this configuration (ITEAD_SONOFF_BASIC):

#define BUTTON1_PIN 0
#define BUTTON1_MODE    BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define BUTTON1_RELAY   1
#define BUTTON2_PIN 14
#define BUTTON2_MODE    BUTTON_SWITCH | BUTTON_SET_PULLUP | BUTTON_DEFAULT_HIGH
#define BUTTON2_RELAY   1

if BUTTON2 is closed (BUTTON2_PIN is LOW) and Espurna reboots, then RELAY1 always turns on (even if the state before reset was off).

bug button relay staged for release

Most helpful comment

I have the same issue with BUTTON_MODE = BUTTON_SWITCH.
I think the button state should be read during setup and should not fire a Click event?

Edit:
fixed it. Only a small change in the Debonce Library:

DebounceEvent.cpp (_init Method):

void DebounceEvent::_init(uint8_t pin, uint8_t mode, unsigned long delay, unsigned long repeat) {
    // store configuration
    _pin = pin;
    _mode = mode & 0x01;
    _defaultStatus = (mode & BUTTON_DEFAULT_HIGH) > 0;
    _delay = delay;
    _repeat = repeat;

    // init button state    
    _status = ((mode & BUTTON_SWITCH) > 0) ? digitalRead(_pin) : _defaultStatus;

I've no BitBucket, so somone else could do a PR there?

PS: Boot mode (Always on and Always off) is working with toggle switches too, after this change!

>All comments

I have the same issue with BUTTON_MODE = BUTTON_SWITCH.
I think the button state should be read during setup and should not fire a Click event?

Edit:
fixed it. Only a small change in the Debonce Library:

DebounceEvent.cpp (_init Method):

void DebounceEvent::_init(uint8_t pin, uint8_t mode, unsigned long delay, unsigned long repeat) {
    // store configuration
    _pin = pin;
    _mode = mode & 0x01;
    _defaultStatus = (mode & BUTTON_DEFAULT_HIGH) > 0;
    _delay = delay;
    _repeat = repeat;

    // init button state    
    _status = ((mode & BUTTON_SWITCH) > 0) ? digitalRead(_pin) : _defaultStatus;

I've no BitBucket, so somone else could do a PR there?

PS: Boot mode (Always on and Always off) is working with toggle switches too, after this change!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lfarkas picture lfarkas  路  4Comments

pidiet picture pidiet  路  7Comments

Chrisuli picture Chrisuli  路  7Comments

vaidyasr picture vaidyasr  路  10Comments

mstjerna picture mstjerna  路  6Comments