Giter Club home page Giter Club logo

vera-mqtt's Introduction

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:

{"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

vera-mqtt's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vera-mqtt's Issues

Consider adding polling for user-specified variables

Currently the vera mqtt client only publishes variable values whenever a variable's value changes. This satisfies most use cases with an efficient propagation of data however in some cases, the dataset is too sparse for convenient analysis. It would be useful to allow users to specify variables that should be watched and/or polled at some periodicity. For example, polling TemperatureSensor1 or HumiditySensor1 or other variables would allow users to build a continuous dataset for certain sensors. In addition, a new companion mqtt client variable called mqttVariablePollingInterval should be added that allows users to specify the polling interval in seconds.

The existing user interface could be extended to include a second "polling" column that when checked, will add polling for the variable. Another option would be to add a second "Polling" tab.

MQTT Client does not reconnect

There is an invalid assumption that client:publish() returns an error if the client fails to publish a message to the mqtt broker. As a result, the vera client never reconnects to the broker because the tests for ~= nil after invoking :publish() never hold true.

It seems the lua mqtt client is not only incomplete, there is no one actively developing it any more therefore a quick and dirty fix that should work is to simply return the result of the client:message_write() from the client:publish() method.

Port plugin to dkjson

It seems that MIOS/Vera has standardized on dkjson for json decoding and encoding. To reduce the dependencies on UI6+, we should port the plugin to dkjson.

Ability to respond to variable queries over MQTT

It would be good to extend the SensorMqtt plugin to include a relatively benign subscription as a "request/response" proof of concept for controlling a Vera remotely over MQTT. Other adventurous souls could expand the set of actions to address more use cases.

Concept

Implement a relatively benign topic action that allows a remote mqtt client to request an update for one or more service variables.

Design

  • If a service variable request includes device id, then the variable will only be returned for that device.
  • If a service variable request does not specify a device, then the variable will be returned to all devices that provide the requested service variable.
  • The service variable requests are encoded as a JSON array allowing the remote client to request one or more variables in a single request

Service Variable Request Topic

/Vera/(SerialNumber)/GETVARIABLE

Payload Example

{
    [
      {"ServiceId: "urn:upnp-org:serviceId:TemperatureSensor1", "Variable": "CurrentTemperature"},
      {"ServiceId: "urn:upnp-org:serviceId:HumiditySensor1", "Variable": "CurrentLevel", "DeviceId": 49}
   ]
}
  • The first element requests the current temperature from all TemperatureSensor devices.
  • The second element requests the current humidity from device 49

Client does not reliably reconnect to broker

If the client connection is severed by the broker, then the client will not reliably reconnect. This is due to edge cases for the currently implemented connection state machine. For example, in the current implementation, the client will not resume periodic mqtt pings via the MQTT.client.handler() method.

Extend Connection Model to attempt re-connect based upon user-supplied reconnect interval

Currently the MQTT client is a publish only client however the underpinnings for a persistent connection model are already in place. Currently, the client will not reconnect to the broker unless it has something to publish. To improve future support for subscription support, the connection model should be extended to reconnect after a user-specified interval elapses. This is a very straight-forward change - check if the reconnect interval has elapsed in the processMQTTevents() method and if so, attempt to reconnect to the broker.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.