I am using your integrated mqtt provided methods and they work well except it seems like I can only subscribe to one topic at a time for the whole hubitat enviroment? Is this intentional or am I missing something? I would like to monitor a topic for each device.
You can just issue consecutive mqtt subscribe requests to any number of arbitrary topics. You can wildcard the subscriptions too if that helps. Make sure you keep the connection open as once closed you’ll lose any previous subscriptions.
You can separate the responses in the drivers parse method based on the returned topic
That works if you have subscribes across drivers but if you have multiple devices utilizing the same driver that is not the case. You will only recieve the parse callback from the last device that initialized the subscribe.
That’s not how it works. I only use one driver in my app/driver but it handles unlimited subscribes and of course publishes. I sort out which topic is reporting based on the single parse routine in my single driver. It is called for every change in a subscribed payload. They have to be on the same broker of course.
What relationship does your device driver have to the MQTT driver. Are you using an app ?
I am using the built in MQTT interface.
https://docs.hubitat.com/index.php?title=MQTT_Interface
my driver is here HAIMqttOmniBridge/HAIMqttOmniBridge-Zone at master · mikec85/HAIMqttOmniBridge · GitHub
It works great when only using one device per driver but when I add the second device only one of the devices will recieve the message via the parse function. Currently looking at doing a parent child setup to get around the limitation.
The MQTT specification requires a unique client id. You cannot make 2 connections to the same broker with the same client ids, they must be unique. Your second connection is kicking the first connection offline. You must generate a unique id for the client id, either use the device id as part of the client id or figure out some other way to generate a unique id.
That being said, maintaining one connection with child devices is actually a better option instead of having each device open its own connection to the broker.
Each time you run your device code you are creating a new connection to the MQTT broker but using the same clientID . This will terminate any previous connections so you will end up with only the last one.
Either you need to open new connections with different clientIDs or preferably you should have one MQTT device and call into that to setup you subscriptions. The parse routine in the MQTT device can distribute returned parse events to the appropriate device.
Sorry Chuck... overlapped response but happy we said the same.
Mike - my MQTT app is in alpha but pretty stable and feature complete so will be in open beta shortly. If you want to be in the alpha test group then just let me know by PM
Not sure what your ultimate goal is for your app but mine might already do what you need ?