cflurin / homebridge-mqtt

Homebridge-mqtt is a Plugin for Homebridge.
Apache License 2.0
229 stars 39 forks source link

pulling sensors from adafruit.io to homekit through homebridge and mqtt #107

Closed tenpn closed 3 years ago

tenpn commented 3 years ago

hi folks, I might be trying to put a round peg in a square hole, so please tell me if so.

I have a pi running homebridge already, and separately some sensors sending temp data to adafruit.io. I figured cuz adafruit supports mqtt, I'd be able to bring the sensors into homebridge and have them appear in my phone's home app by "just" connecting them using this plugin.

adafruit.io's mqtt docs are here: https://learn.adafruit.com/adafruit-io/mqtt-api

when I add the plugin, set the config URL to mqtt://io.adafruit.com, and set up my credentials, I get the following error:

[17/05/2021, 10:14:36] [mqtt] on.error Error: Connection refused: undefined
    at MqttClient._handleConnack (/usr/local/lib/node_modules/homebridge-mqtt/node_modules/mqtt/lib/client.js:1190:15)
    at MqttClient._handlePacket (/usr/local/lib/node_modules/homebridge-mqtt/node_modules/mqtt/lib/client.js:424:12)
    at work (/usr/local/lib/node_modules/homebridge-mqtt/node_modules/mqtt/lib/client.js:321:12)
    at Writable.writable._write (/usr/local/lib/node_modules/homebridge-mqtt/node_modules/mqtt/lib/client.js:335:5)
    at doWrite (/usr/local/lib/node_modules/homebridge-mqtt/node_modules/readable-stream/lib/_stream_writable.js:409:139)
    at writeOrBuffer (/usr/local/lib/node_modules/homebridge-mqtt/node_modules/readable-stream/lib/_stream_writable.js:398:5)
    at Writable.write (/usr/local/lib/node_modules/homebridge-mqtt/node_modules/readable-stream/lib/_stream_writable.js:307:11)
    at Socket.ondata (internal/streams/readable.js:719:22)
    at Socket.emit (events.js:315:20)
    at addChunk (internal/streams/readable.js:309:12) {
  code: 6
}

if I set the config url to http://io.adafruit.com, I get

[17/05/2021, 10:22:07] [mqtt] connected (url = https://io.adafruit.com)
[17/05/2021, 10:22:07] [mqtt] on.offline <to analyze>
[17/05/2021, 10:22:07] [mqtt] on.close <to analyze>
[17/05/2021, 10:22:07] [mqtt] connect error! (url = https://io.adafruit.com)
[17/05/2021, 10:22:08] [mqtt] on.reconnect <to analyze>

I currently still have the topic_type and _prefix set to their default "multiple" and "homebridge", if that's impacting things. I figured I'd start messing with those once I get some

cflurin commented 3 years ago

homebridge-mqtt only works with a mqtt broker (url: mqtt://...).

tenpn commented 3 years ago

yep, adafruit.io is a broker (it's mentioned in a broker list here https://learn.adafruit.com/alltheiot-protocols/brokers-clients and in other places in the docs). so if mqtt is the right choice, what do you think those errors mean?

and would homebridge-mqtt support pulling sensor data from a broker and making it available in the home app? do you know of any example configs to look at for that?

cflurin commented 3 years ago

As I said the protocol is MQTT, so your url should start with mqtt:// nad not https://

tenpn commented 3 years ago

yep that was my first attempt, which led to the "Connection refused: undefined" error. I only tried http then. the first error is in the OP.

cflurin commented 3 years ago

Sorry, I've never used the adafruit broker so I can't help here.

Edit: Tip: install the MQTT explorer and try to connect to the adafruit broker.

tenpn commented 3 years ago

I'll try the explorer! can you help with the second part of the question? do you think homebridge could work like this, pulling feeds from a broker and displaying them as sensors in the home app?

tenpn commented 3 years ago

(I got the explorer to connect by subscribing to tenpn/feeds/#. I tried setting topic_prefix on homebridge-mqtt to tenpn/feeds/ stopped me getting errors in the log. It now says I'm connected. I'm no closer to setting up the feeds as accessories, tho.