Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SonOff Touch stability issues #327

Closed
xoseperez opened this issue Dec 14, 2017 · 6 comments
Closed

SonOff Touch stability issues #327

xoseperez opened this issue Dec 14, 2017 · 6 comments

Comments

@xoseperez
Copy link
Owner

Originally reported by: Yann LEFEBVRE (Bitbucket: Battosai30, GitHub: Battosai30)


Hi,

I tested your firmware but I met a lot of stability problems and I think I localised it. So I have stability issues when I press the button several times in a row (sometimes just a double click is enough). Sometimes the module reboots and sometimes it just restart the wifi connexion. I also noticed that joining my network (beforehand added in web interface) could be very long.

I tried .bin 1.10.1 and I tried recompiled in Arduino with minimalist function activated and the results are the same. First I thought it was a power issue, so I added a capacitor => no effect and I tested with another supply source ==> no effect too. So I rewrote my own little firmware to connect to my wifi, and upload information on my MQTT broker and it works very well. I think I found some potentials problem sources but did not had the time to test it for now.

Regards

@xoseperez
Copy link
Owner Author

Original comment by Kruno M (Bitbucket: Kruu51, GitHub: Unknown):


Yes, I also got my first Touch. Flashed it and the same problem here. But When I disable mqtt and domoticz it works OK for now.

@xoseperez
Copy link
Owner Author

Original comment by nkerezov (Bitbucket: nkerezov, GitHub: nkerezov):


Have you guys tryed earlyer version of espurna-sonoff-touch?

@xoseperez
Copy link
Owner Author

Original comment by Yann LEFEBVRE (Bitbucket: Battosai30, GitHub: Battosai30):


I tried with 1.10.0 => same result

So I just simplified the button routines to that :

#!arduino


void buttonSetup()
{
  pinMode(0, INPUT);
}
void buttonLoop()
{
    static byte flag = 0;
  if (!flag && digitalRead(0) == LOW)
  {
    flag = 1;
        char payload[2];
    snprintf_P(payload, sizeof(payload), PSTR("%d"), 1);
    mqttSend(MQTT_TOPIC_BUTTON, 0, payload);
  }

  if (digitalRead(0) == HIGH && flag)
  {
    flag = 0;
        char payload[2];
    snprintf_P(payload, sizeof(payload), PSTR("%d"), 0);
    mqttSend(MQTT_TOPIC_BUTTON, 0, payload);
  }
}

And it works. I can spam the button, it does not seems to crash and MQTT is well updated. It confims my first diagnostic and it explains why no one else has this kind of problem on others sonoff modules.

As the crash does not always lead to a complete reset, I suspect a memory leak or something of this kind. I have not more time this week to investigate but I found that :

#!arduino

unsigned long buttonStore(unsigned char pressed, unsigned char click, unsigned char dblclick, unsigned char lngclick, unsigned char lnglngclick) {
    unsigned long value;
    value  = pressed;
    value += click << 4;
    value += dblclick << 8;
    value += lngclick << 12;
    value += lnglngclick << 16;
    return value;
}

You're shifting unsigned char by more that 8 without any cast or conversion, so the differents values may be lost during the shifting. I added a conversion but it didn't solve the issue.

@xoseperez
Copy link
Owner Author

The issue you are describing it's the default behaviour for ESPurna buttons (double click means AP mode, long click reset). But you are right it does not make sense for wall switches like the TOUCH or the T1, instead I have changed the default behaviour to:

    #define BUTTON1_MODE        BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
    #define BUTTON1_PRESS       BUTTON_MODE_TOGGLE
    #define BUTTON1_CLICK       BUTTON_MODE_NONE
    #define BUTTON1_DBLCLICK    BUTTON_MODE_NONE
    #define BUTTON1_LNGCLICK    BUTTON_MODE_NONE
    #define BUTTON1_LNGLNGCLICK BUTTON_MODE_RESET

So it will toggle on press and only reset on long long click (more than 10 seconds holding the button). Changing that configuration in the hardware.h file should fix the "stability" issues you describe.

But you are right about the casting issue in the buttonStore method.

@xoseperez
Copy link
Owner Author

Original comment by Yann LEFEBVRE (Bitbucket: Battosai30, GitHub: Battosai30):


Ow ok, it makes sense :)

Thank you I will test it ;)

@xoseperez
Copy link
Owner Author

Removing milestone: 1.11.3 (automated comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant