MQTT To Virtual Thing Adapter

Here’s an interesting idea for those who are interested! Sadly I don’t have the time to actually do it :cry: (new job, first daughter coming)

There’s an adapter already created for virtual things, this allows us to play around with, well, virtual things, but what if we could map those virtual things to MQTT topics & messages?

So, an example:

After configuring the MQTT broker settings, a user would be able to map:

  • An OnOffProperty could be mapped to 2 MQTT topics (but usually the same) with a configurable message…
  • Similarly a BrightnessProperty could be mapped to 2 MQTT topics, just as before to read & write the value set.

This approach is what about a 100% of MQTT dashboards for android use, and could be the missing link for wider adoption.

There’s a basic MQTT adapter implementation https://github.com/hobinjk/mqtt-adapter

I’m not sure how current it is and I am also pretty sure that it was built more as a starting point to implement a specific MQTT dialect rather than usage as a generic, configurable MQTT adapter.

(I think the way you use “virtual thing” is how all adapters think of their things)

This adapter is not finished, I started to make mine and it’s still not yet published but meanwhile you can implement webthings to bridge mqtt to rest…

Maybe I should upstream this in webthing-node 1st or any other project ?

I am considering taking this on - at least for starters.
I greatly like the idea of starting from the virtual thing base.

One thing that would help me however is if I could simply bridge existing things instances (virtual or otherwise) with an MQTT client (I would write). I.e. bridge properties and events of things that currently live in the running gateway with my own code - which will connect to the MQTT broker.

But I have a feeling that this would be “hacking into the backdoor” and therefore probably not allowed/enabled.

Maybe @mrstegeman or @bfrancis can point me in the right direction?

@t1m1 has several add-ons that publish property data to other sources. For example, he created the azure-iot-bridge add-on. That may be a good place to start.

I’ve also created a very simple adapter at https://github.com/MichaelKohler/simple-mqtt-adapter/. In the config you can specify the following:

  • Topics to subscribe to -> creates “events” on a virtual thing which then can be used in rules
  • Topics to publish to -> creates “actions” on a virtual thing which then can be used in rules, or in the GUI

You might be able to use that to connect your things to an MQTT instance using rules. It’s super basic right now, but covers my own use case.

Thank you both, I’ll definitely look into your suggestions.