Author Topic: MQTT Client Plugin  (Read 28211 times)

Offline SchattenMann

  • Sr. Newbie
  • *
  • Posts: 42
  • Karma: +4/-1
MQTT Client Plugin
« on: January 19, 2016, 08:34:47 am »
MQTT Client Plugin

This plugin provides the ability to publish out any user defined variable to an MQTT Broker.
It is based on the code found here
This is my first plugin so odds are there will be some bugs although so far seems to be working fine.

This plugin is designed for use on systems running UI7.

Features

  • User defined Variables to watch
  • User defined Device Alias which makes Logic much more intuitive and makes it easier when replacing devices

MQTT Message Example

Code: [Select]
{"Payload":{"DeviceId":45,"OldOnOff":"1","OnOff":"0","Time":1453209965},"Topic":"Vera/Events/TestSocket"}
Installation and Configuration

  • Upload the attached files
  • Create a new device with device_file set to D_SensorMqtt1.xml
  • Set desired variable watches on the Watchdog tab
  • (optional) Set desired Alias on the Alias tab
  • Have fun


Dependencies


There are a few dependencies that should be copied to /usr/lib/lua folder

Source code

https://github.com/jonferreira/vera-mqtt
« Last Edit: August 28, 2016, 03:15:28 pm by SchattenMann »

Offline 4integration

  • Sr. Newbie
  • *
  • Posts: 47
  • Karma: +0/-0
Re: MQTT Client Plugin
« Reply #1 on: January 19, 2016, 10:09:35 am »
Really nice, great!

Would be even nicer if some screenshots were added :)

Offline Snaxmuppet

  • Newbie
  • *
  • Posts: 17
  • Karma: +1/-0
Re: MQTT Client Plugin
« Reply #2 on: January 19, 2016, 10:19:25 am »
Thank you.

I shall try it out later :)

Offline Snaxmuppet

  • Newbie
  • *
  • Posts: 17
  • Karma: +1/-0
Re: MQTT Client Plugin
« Reply #3 on: January 19, 2016, 11:52:55 am »
I am stuck. How do I upload those files to the Vera?

Offline SchattenMann

  • Sr. Newbie
  • *
  • Posts: 42
  • Karma: +4/-1
Re: MQTT Client Plugin
« Reply #4 on: January 19, 2016, 12:39:40 pm »
I suppose you're both talking about the dependencies...
These need to be uploaded to /usr/lib/lua folder as explained on the first post.
You can do this via SSH or with WinSCP

Offline SchattenMann

  • Sr. Newbie
  • *
  • Posts: 42
  • Karma: +4/-1
Re: MQTT Client Plugin
« Reply #5 on: January 19, 2016, 12:40:37 pm »
Really nice, great!

Would be even nicer if some screenshots were added :)

That's the next step, just run out of time

Offline Snaxmuppet

  • Newbie
  • *
  • Posts: 17
  • Karma: +1/-0
Re: MQTT Client Plugin
« Reply #6 on: January 19, 2016, 04:28:30 pm »
I suppose you're both talking about the dependencies...
These need to be uploaded to /usr/lib/lua folder as explained on the first post.
You can do this via SSH or with WinSCP
But what is the ssh I'd and password then?
I've only ever logged on via the Web site.

Offline SchattenMann

  • Sr. Newbie
  • *
  • Posts: 42
  • Karma: +4/-1
Re: MQTT Client Plugin
« Reply #7 on: January 20, 2016, 04:39:19 am »
I suppose you're both talking about the dependencies...
These need to be uploaded to /usr/lib/lua folder as explained on the first post.
You can do this via SSH or with WinSCP
But what is the ssh I'd and password then?
I've only ever logged on via the Web site.

username is root and password is your Vera's Wireless Password

Offline SchattenMann

  • Sr. Newbie
  • *
  • Posts: 42
  • Karma: +4/-1
Re: MQTT Client Plugin
« Reply #8 on: January 20, 2016, 05:13:05 am »
UI screenshots attached

Offline Snaxmuppet

  • Newbie
  • *
  • Posts: 17
  • Karma: +1/-0
Re: MQTT Client Plugin
« Reply #9 on: January 20, 2016, 08:05:18 am »
When I try to WS-FTP in to the Vera using SSH I get the following:

Error 842c0000 receiving sftp packet
error 842c0000 initializing sftp protocol
Sending channel close message for channel 0760a2ce
SSH Transport closed.

I can log in using SSH command line using Putty though.

Is there any documentation on this? I don't want to have to keep pestering you all the time... that isn't fair on you :)

Offline SchattenMann

  • Sr. Newbie
  • *
  • Posts: 42
  • Karma: +4/-1
Re: MQTT Client Plugin
« Reply #10 on: January 20, 2016, 08:14:43 am »
When I try to WS-FTP in to the Vera using SSH I get the following:

Error 842c0000 receiving sftp packet
error 842c0000 initializing sftp protocol
Sending channel close message for channel 0760a2ce
SSH Transport closed.

I can log in using SSH command line using Putty though.

Is there any documentation on this? I don't want to have to keep pestering you all the time... that isn't fair on you :)

Not sure if SFTP will work (never tested it myself) but WinSCP definitely does.

Beware though you have to disable "Secure my Vera" first under Users & Account Info - Unit Settings

Offline Snaxmuppet

  • Newbie
  • *
  • Posts: 17
  • Karma: +1/-0
Re: MQTT Client Plugin
« Reply #11 on: January 20, 2016, 08:59:07 am »
Thx. Used WinSCP.

So I have uploaded the dependencies to the correct location and added the plugin files to the Luup files via the dashboard.

Now I am stuck again... how do I create the device? I have tried via the Device Add process and I can see nothing to do with MQTT in the list of possible devices. I have tried to add a device via the develop apps but I don't know what to enter for the various fields.

This is why I asked if there was some documentation on how to add new plugins.

Sorry to pester.

Offline SchattenMann

  • Sr. Newbie
  • *
  • Posts: 42
  • Karma: +4/-1
Re: MQTT Client Plugin
« Reply #12 on: January 20, 2016, 09:01:49 am »
Thx. Used WinSCP.

So I have uploaded the dependencies to the correct location and added the plugin files to the Luup files via the dashboard.

Now I am stuck again... how do I create the device? I have tried via the Device Add process and I can see nothing to do with MQTT in the list of possible devices. I have tried to add a device via the develop apps but I don't know what to enter for the various fields.

This is why I asked if there was some documentation on how to add new plugins.

Sorry to pester.

Sorry, so used to this that I've forgotten to add that information.
screenshot attached

Offline Snaxmuppet

  • Newbie
  • *
  • Posts: 17
  • Karma: +1/-0
Re: MQTT Client Plugin
« Reply #13 on: January 20, 2016, 11:37:08 am »
Right... we are getting there.

So I now have the device in my devices list. What now?

How can I send a MQTT message to my MTTT broker with, say, the status of one of my Vera controlled devices?

How can I read a topic from the MQTT broker and then say, activate a device on the Vera?

Can I do these things?

You wouldn't believe I am a very experienced software developer of 30+ years would you... I feel like a total noob.

Offline SchattenMann

  • Sr. Newbie
  • *
  • Posts: 42
  • Karma: +4/-1
Re: MQTT Client Plugin
« Reply #14 on: January 20, 2016, 01:27:23 pm »
So I now have the device in my devices list. What now?

My apologies, I?d forgotten about the initial configuration (I?m planning to release a quick guide anytime soon but haven?t got the time yet)

On the Advanced ? Variables tab set your MQTT Broker IP (mqttServerIp) and Port (mqttServerPort)

How can I send a MQTT message to my MTTT broker with, say, the status of one of my Vera controlled devices?

Simply subscribe a device variable on the "Watchdog" Tab. Say you want to receive notifications when a Relay Is Turned On/Off - subscribe the urn:upnp-org:serviceId:SwitchPower1 - Status Variable

How can I read a topic from the MQTT broker and then say, activate a device on the Vera?

This Plugin is just for Publishing MQTT messages to a MQTT Broker

Hope this help