-
Notifications
You must be signed in to change notification settings - Fork 639
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
MQTT -> Publish button status #1747
Comments
Thanks for the hint. Unfortunately this doesn't help. Subscribing to relay/0 or 1 gives me immediately status "0" indicating the relay is off. Subscribing to button/0 or 1 gives me nothing. When connecting the according pin with gnd it gives me 2,3 or 4. I would really like to get state "0" for open buttons and something else for closed ones. |
Right, but that can only happen when espurna sends out mqtt with retain flag. That way, mqtt broker saves the last published message and will send it out to every subscriber on initial connection, until the device (or something else) sends something different or deletes it. Note that 3c2b201 did explicitly remove this behaviour: espurna/code/espurna/button.ino Line 32 in 9ceca44
We can add a setting, maybe? btnRetain , BUTTON_MQTT_RETAIN define, 0 or 1, to control this
And idk if you'd want that, but based on config above buttons will still change relay state. When button action is set to NONE, to still receive button events espurna/code/espurna/button.ino Lines 103 to 105 in 9ceca44
|
Thanks for the info. Now I know that it's nothing i oversaw but "works as designed". I use a Sonoff Dual R2 to open and close slides on my grass mower's garage. I intend to use the two additional buttons to sense the mower in the garage and the slides being opened or closed. Thus, inventing a configurable retain feature for the buttons (and relays) would be great. I followed your hint regarding button.ino and changed Thanks for your big help and maybe a configurable "retain" might make it into one of the next versions. Oh, and I think I configured the buttons not to switch the relays in defaults.h. At least they don't currently switch but only report state. |
mini reminder: github will not send notifications for edits! i just accidentally noticed this in gitter window That should've worked. With small code snippet in terminal setup(): terminalRegisterCommand(F("TEST"), [](Embedis* e) {
mqttSend(MQTT_TOPIC_BUTTON, 0, "1", false, true); // send 1 with retain flag
delay(100);
mqttSend(MQTT_TOPIC_BUTTON, 0, "2", false, false); // send 2 without retain
}); Running
|
Thanks. While I'm not that good in Terminal I checked with MQTT Box on MacOS which supports subscribe & publish to topics. The code modification has worked so far that when I subscribe to the buttons, I receive an initial When I connect button with gnd I always receive a 2 with retain:false which is ok. Unfortunately there is no 0 sent when I disconnect the bridge. I assumed, with BUTTON_MQTT_SEND_ALL_EVENTS this would also be sent. This is the only thing which prevents me from using MQTT to check the state of the button. |
espurna/code/espurna/config/types.h Lines 32 to 39 in 0998110
If button is configured as PUSHBUTTON, we receive a bunch of events that depend on connection/disconnection count and their longevity, ref the header values above. I think there is a slight misunderstanding of what 0 actually is. It only happens in this mode and when we do something event mapper does not understand as any other event type for example: if event 1 received 4 times in a row, we can't map it to anything and send 0 (NONE)
And if it is SWITCH, we receive event 2 (BUTTON_EVENT_RELEASED / BUTTON_EVENT_CLICK) when contact is connected or disconnected. So retaining this is of no use. I do hope I properly understood that the issue here is that we only receive event, not the actual status. We can't exactly avoid event mapper right now (but it is something to maybe change ever slightly), but we can use EventSensor instead of button. See #1771 and code/espurna/config/sensors.h for info about it's configuration. I added specific option when trigger mode is enabled to retain last read pin value. |
Thanks for your help. BUTTONS really don't work like I expected them to. I read #1771 and sensors.h but couldn't figure out how to configure this for my purpose. |
EventSensor minimal config would be
But, as noted in the PR, it can be imprecise for this purpose (within interrupt, digitalRead can sometimes return surprising results. and due to Core limitations and compatibility with Arduino API we are kind of stuck with it) |
I compiled with the above mentioned EventSensor values with EVENTS_PIN set to 9 which should be BUTTON1 on the Sonoff Dual R2. When I subscribe to MQTT I see event being 0. When I connect BUTTON1 with GND nothing happens. Compiling with EVENTS_PIN set to 0 also nothing happens when connecting BUTTON0 with GND. And idea? Also how do I configure to check for BUTTON1 and BUTTON0? Thanks. |
EVENTS_PIN_MODE needs to be INPUT_PULLUP with some pins (ref button modes that sets it as such) |
That's my not working config:
As I'm not good at all in patching source code from github I'll wait for #1772 to be merged into the code. So I haven't tried, yet. |
The events sensor "event" is a logical read. So connecting GND would give 0 and 3v3 - 1. #1772 configuration proposes additional "reporting mode", so that each button can be either sending events or pressed status. I do wonder it bitmasks are needed though and that can just be some global setting like BUTTON_MQTT_SEND = BUTTON_MQTT_SEND_PRESSED, as it was in the 515e660 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. |
This issue will be auto-closed because there hasn't been any activity for two months. Feel free to open a new one if you still experience this problem. |
I publish from my Sonoff Dual R2 to my Mosquitto Broker on my Synology.
When I read /home/relay/0 any time I get the current state (0 or 1). This also applies to relay/1.
When I read /home/button/0 I get no result. I see its status is published but would like to read it any time using phpMQTT.
So generally I'd like to see button/0 and button/1 behave like relay/0 and relay/1.
Is this something I can configure somewhere, a bug or a feature request?
In hardware.h I defined:
The text was updated successfully, but these errors were encountered: