Closed undrwater closed 4 years ago
Hey @undrwater - thanks for giving this a try! I just pushed an updated version (0.1.3) that might give you a bit more details about the error - I/O isn't particularly insightful 😅.
That said, if I had to guess from the messages above, it seems like the wink can't connect to your MQTT broker. Could you make sure that you allowed external connections to your broker? Specifically, if you are running the broker on a linux machine, you should see something like this:
$ sudo netstat -ap | grep 1883
tcp 0 0 0.0.0.0:1883 0.0.0.0:* LISTEN 1536/mosquitto
the 0.0.0.0:*
is the important bit here. If you're using mosquitto, I think bind_address
is the config option you want to clear to allow connections from anywhere.
Separately, if you get openhab autodiscovery working, I'd love to put a "how" on the readme! Let me know how I can help.
I think I'm having challenges with the terminology here. For instance, I assumed the "broker" is your software running on the Wink Hub.
I think I need to better understand this point:
it seems like the wink can't connect to your MQTT broker. Could you make sure that you allowed external connections to your broker?
I've done some googling as I like to figure things out on my own, but I think since the Wink is an edge case, I'm having a harder time.
I'll install the new version and see what happens! :+1: Thanks for sticking with me. And for sure, I'll let you know if and how OpenHab ends up working.
So in MQTT there's several different "roles" different software plays. Specifically - there's publishers, subscribers and brokers. This is a little different than HTTP. The main benefit of MQTT for IOT is that the communication is two-way - devices can send updates and receive commands without anyone "prompting" them. HTTP is more of a one-way protocol so a lot of IOT instead reverts to asking the status once every e.g. 10 seconds. Here is a great diagram I found that tries to explain MQTT:
In MQTT the "broker" is a standalone program that connects subscribers to publishers. Both openhab & wink-mqtt-rs are MQTT clients. MQTT is a standard so there are many different broker packages you can use, but mosquitto is the most common one. I haven't used openhab but if you're using openhabian or similar it looks like there might be a way to install mosquitto from the customization UI? Otherwise you can always run docker run -it --name mosquitto -p 1883:1883 eclipse-mosquitto
for testing.
Separately, seems like there would be some appetite for an HTTP server in wink-mqtt-rs that just exposes some of these things via REST. I'll put that on a list of features to add - it should be pretty easy.
Fantastic! The new log was more useful:
err: Io(Os { code: 111, kind: ConnectionRefused, message: "Connection refused" })
So, with your explanation (and the following OpenHab document), I realized that I need to set up mosquitto on my server. Here's the OpenHab doc: https://www.smarthomeblog.net/mqtt-openhab/
I'm working on getting mqtt (mosquitto) worked out on the server. I'll let you know when I work that out.
@undrwater thanks - let me know if I can be helpful! Looking forward to the experience report.
OK. I had some problems with my OpenHab install, but everything's good now.
I was able to install mosquitto on my openhab server and get it running. I think what I need to figure out now, is how to set the configs so that mosquitto and wink-mqqt-rs see each other.
I'm still getting connection refused error. Other than the URI, what is required on the config to make sure it sees the broker? The broker for sure is running on the same box as OpenHab. Is there something in the mosquitto config that is needed?
Thanks for your patience!
Getting a little further. Decided to start things manually since I wasn't getting any logs from mosquitto. Here's what I'm getting from wink-mqtt-rs:
/opt/wink-mqtt-rs/wink-mqtt-rs -s mqtt://192.168.1.19
Oct 02 18:16:33.370 INFO init_logger, min_log_level: Info Oct 02 18:16:33.407 INFO starting, version: 0.1.3 Oct 02 18:16:33.611 INFO opening_client, client_id: wink-mqtt-rs, port: 1883, host: 192.168.1.19 Oct 02 18:16:33.661 INFO poller_starting, resync_interval: 10000
and from mosquitto:
1601662663: Sending PINGRESP to wink-mqtt-rs 1601662663: Received PUBLISH from wink-mqtt-rs (d0, q1, r1, m1, 'home/wink/2/status', ... (47 bytes)) 1601662663: Sending PUBACK to wink-mqtt-rs (m1, rc0) 1601662671: Received PUBLISH from wink-mqtt-rs (d0, q1, r1, m1, 'home/wink/1/status', ... (15 bytes)) 1601662671: Sending PUBACK to wink-mqtt-rs (m1, rc0) 1601662672: Received PUBLISH from wink-mqtt-rs (d0, q1, r1, m1, 'home/wink/2/status', ... (47 bytes)) 1601662672: Sending PUBACK to wink-mqtt-rs (m1, rc0) 1601662681: Received PUBLISH from wink-mqtt-rs (d0, q1, r1, m1, 'home/wink/1/status', ... (15 bytes)) 1601662681: Sending PUBACK to wink-mqtt-rs (m1, rc0) 1601662682: Received PUBLISH from wink-mqtt-rs (d0, q1, r1, m1, 'home/wink/2/status', ... (47 bytes)) 1601662682: Sending PUBACK to wink-mqtt-rs (m1, rc0) 1601662695: Received PINGREQ from f9e94ac8-949f-41f0-bc3f-57ada7fc5efa 1601662695: Sending PINGRESP to f9e94ac8-949f-41f0-bc3f-57ada7fc5efa 1601662700: Received PUBLISH from wink-mqtt-rs (d0, q1, r1, m1, 'home/wink/1/status', ... (15 bytes)) 1601662700: Sending PUBACK to wink-mqtt-rs (m1, rc0) 1601662705: Received PUBLISH from wink-mqtt-rs (d0, q1, r1, m1, 'home/wink/2/status', ... (47 bytes)) 1601662705: Sending PUBACK to wink-mqtt-rs (m1, rc0
Better, no? At this point, would HomeAssistant be able to automatically detect the devices connected to the Wink?
Yep that looks better! I think it likely would have worked without you starting the process manually - there's just not a message for a "successful" connection - the errors just stop happening every second.
For home assistant you would have to activate mqtt auto-discovery -- but yes, everything should work. On the wink, this needs a -d homeassistant/
flag. On the home assistant box, you would need to also connect it to the broker. Here's an example from my home setup: https://github.com/mikekap/raspberrypi/blob/master/home-assistant/configuration.yaml#L25-L27
I was missing tne -d homeassistant. And now...for some reason, the Wink has left the network. It has a blue light, but neither the Wink app, nor my networking apps can find it. I'm going to have to check what's going on via UART again.
Nevermind. It's back. Still not autodetecting though. Speaking with folks on #openhab on freenode, it seems this binding is "not quite there yet". Working on my install of HA.
Do you find your Wink is stable? If this happens frequently enough, I may have to move to another solution (zwave dongle or other...).
SUCCESS!
I was able to turn on the light on my front porch. It's a simple switch, but I'm jazzed. Now I'm working on the bathroom light which has a dimmer. A little more involved.
I had to run this from the command line, as for whatever reason, the init script is not working. I have each switch on a separate line, so I'll experiment putting them on the same line.
Thank you so much! I'll write up how I managed this in OpenHab (it's a manually added "Generic Thing").
Off topic: do you know what the socat
command is doing on the Wink? It uses quite a bit of CPU cycles. Sometimes as much as 80%. I killed it before the unit became unstable the way I mentioned above.
Hey glad to hear you were able to make it work! Sorry openhab directly didn’t work out - I was hoping this might be an easy drop in but I guess not. I’d be happy to add a few install guides here if you’d like to submit a PR!
I’m concerned that the init script isn’t working for you. I actually updated the script in the latest release to set a PATH but you would see some errors in the log file about not finding aprontest. I only ran into that when I tried to use the script without a shell - e.g. “ssh root@wink /etc/rc.d/init.d/wink-mqtt-rs restart”. Would you mind writing the exact sequence of commands you’re using as well as the contents of the log file (/var/log/wink-mqtt-rs.log)? I’d love to fix it for everyone that’s experiencing issues.
I’m not sure what socat is doing. Seems a little strange that it’s there - my wink doesn’t have it as a persistent process. Maybe some kind of update, local control via the wink app or connection to one of the relays? Maybe you could find out who it’s talking to via a netstat -ap and finding socat’s pid. Very mysterious.
OpenHab is working, though not via autodetect. It's probably something I need to figure out. I have a bathroom dimmer switch that I can't get to work, another thing I need to figure out.
Also, the init script DOES work. I must have done something incorrectly previously (probably related to the broker). It even starts when the device restarts. I may need to add some kind of cron task to restart the device, because it becomes unresponsive over time.
Here's what the socat reports in top:
socat -u UDP4-RECVFROM:1900,ip-add-membership=239.255.255.250:wlan0,fork,ip-pktinfo,reuseaddr SYSTEM:grep -o -E 'urn:schemas-smartwink:device:SmartWink:1\\|ssdp:all\\|ssdp:discover' | xargs -t -n 1 -r /usr/share/smartwink/discovery-respond $SOCAT_PEER
Finally, I'm going to run HomeAssistant on my server to see if that is easier to work with. I only picked OpenHab because it was in Gentoo's repository and was the first open source smart home service I found. It seems to have a larger community.
Thank you so much once again!
Wow that’s a super weird process. I think it’s trying to respond to ssdp discovery (think like auto detecting wink hubs from your phone app). Maybe I’m just on an old firmware? On my wink that’s handled by the little nodejs server that’s running all the time.
Glad you got it to work in the end! I’ll close this one for now and open a new issue for tracking the http server work.
We have been communicating via reddit, but I ran into some issues with the mqtt server / broker (is this a broker? which one?).
Here's my log:
I can see my devices are detected, which is good, but you notice the errors. Also, when I:
netstat
I'm not seeing port 1883 listed.Also FYI, i'm using OpenHab, but it has the HA mqtt autodetect functionality built into it's mqtt binding.
This is all very new to me, so I'm having trouble figuring out how to troubleshoot.
ETA: This is the Wink Hub 1. config: