tobof / openhab-addons

The next-generation open Home Automation Bus (openHAB)
Eclipse Public License 2.0
39 stars 30 forks source link

MQTT Support #70

Closed mcguiresean closed 7 years ago

mcguiresean commented 7 years ago

Hi @tobof @andreacioni,

This isn't an issue per se but I didn't want to submit a PR for this yet.

I have forked the refactored branch and added MQTT gateway support here

I'm pretty new to Java so it's probably pretty rough but it does work.

For sending messages out to the MySensors network, I've overridden the send sendMessage function of MySensorsWriter class to intercept the message string and pass it on to the MQTT broker. This seemed to be the best way to keep the MQTT connection abstracted from the gateway object, but I'd be grateful for any comments.

For incoming messages from the MQTT broker, I pass the MySensorsReader a PipedInputStream that is fed by a PipedOutputStream that is written to by the Mqtt messageArrived callback. Again, this may or may not be the best solution but it works.

I've had this running for a day or two and it's been solid but it would be good if someone else could test it.

andreacioni commented 7 years ago

@mcguiresean Wonderful news 😀 I have not experience in MQTT technology but I think you did a good work. Have you take a look at this branch from Tim's repository? He started to work on MQTT in the past, so a good idea should be conforming your work to its one. After that you can make a PR on Binding_Refactoring branch that is the current one we use for development. We can continue there this discussion 👍 Thank you!

mcguiresean commented 7 years ago

@andreacioni Thanks for your comments. I actually did some work expanding on Tim's MQTT proof of concept before I noticed that you were doing the major refactoring. I took inspiration from his code for this branch though so there may be quite a few similarities. I'll put in the PR 😀