rickbassham / indi-mqtt-bridge

A bridge between [INDI](https://indilib.org) and MQTT.
ISC License
1 stars 1 forks source link

Issue setting device properties #3

Open robbrad opened 1 year ago

robbrad commented 1 year ago

Hi Rick

I am having issues setting device properties - im noticing the handleMqttMessage is never run due to the subscription

https://github.com/rickbassham/indi-mqtt-bridge/blob/main/src/index.js#L58

This line subscribes to the basetopic/+/+ - I found basetopic/# to work

Can you comment on this have you had it working?

my sample json string that works for my Dragonfly Dome is

{
  "device": "DragonFly Dome",
  "name": "RELAY_4",
  "switches": [
    {
      "name": "INDI_ENABLED",
      "value": "Off"
    },
    {
      "name": "INDI_DISABLED",
      "value": "On"
    }
  ]
}

Sent to indi/data/DragonFly Dome/RELAY_4/newSwitchVector

robbrad commented 1 year ago

basetopic/+/+/+ also works due to the nested nature of my topic structure - I guess part of the issue is stopping the bridge from a never ending loop (but then that should not happen due to the only act on newSwitchVector)

rickbassham commented 1 year ago

Hey Robert, it was working when I tested it (3 years ago), but I haven't done anything with it since. This was more of a proof of concept than anything else.

robbrad commented 1 year ago

All good Rick - I just wanted to check as I was having difficulty working out how to set values in Indilib

Indilib has limited return values when interacting with it even if the payload is incorrect.

I think what you have done here is great and is helping me build some automations into Home Assistant

robbrad commented 1 year ago

What are your thoughts on a code change to only allow the bridge to react to a message to the MQTT topic that contains a "client" parameter?

For example:

{
    "device": "DragonFly Dome",
    "name": "RELAY_4",
    "switches": [
      {
        "name": "INDI_ENABLED",
        "value": "Off"
      },
      {
        "name": "INDI_DISABLED",
        "value": "On"
      }
    ],
    "client":"ha"
  }

The reason for this is that the bridge could receive messages from other INDI clients and then reprocess them, causing a loop.

If I get the bridge to only react if the "client" property is present, then it will only react to certain clients.

I'm happy to submit a PR but wanted your thoughts first. I tested this, and the extra property doesn't interfere with INDIlib.