Code Monkey home page Code Monkey logo

mqttclient's Introduction

icon_running

MQTTClient

This is my simple client that I use to connect to my mqtt client at home to get notifications on events and publishing commands remote. (the typelib-1_0-AppIndicator3-0_1 package needs to be installed on openSUSE leap 15)

Configuration

The configuration file for the application is located at ~/.mqttclient.yaml. When you launch the client for the first time you get the option to copy the default_mqttclient.yaml as a base for your configuration. The configuration file is a standard yaml file The configuration file has the following sections

mqtt

this is where you configure the connection options for your MQTT server

mqtt:
  host: localhost
  port: 1883
  use_tls: true
  user: username
  password: secret
  timeout_reconnect: 60
  logger: mqttclient
  ca_file: /etc/ssl/ca-bundle.pem
  connect_on_launch: true
  subscriptions:
    - name: irssi
      subscribe: true
      qos: 2
      topic: irssi
      plugins:
        - irssi
    - name: test
      subscribe: true
      topic: test
      plugins:
        - notify

The connect_on_launch specifies if mqttclient should connect to mqtt server automaticly when you launch the application or not. Under subscription you specify the topics you want the application to subscribe to and supports wildcards. For example, myhome/floor1/temperature/# would subscribe to all topics under myhome/floor1/temperature while myhome/+/lights/# would subscribe to all topics under lights on all floors. the plugins list specifies all plugins that should be executed when a topic is updated

plugin

Here you can override the plugins default configuration, for example setting the priority on notifcation for the irssi plugin from de default Notify.Urgency.NORMAL to Notify.Urgency.CRITICAL

plugin:
  irssi:
    urgency: critical

publish

This section configures the publish menu when you right click on the application indicator right_click_menu

publish:
  - name: test 1
    topic: test
    qos: 1
    payload: hejsan svejsan
    retain: false
  - name: test 2
    topic: test2/testing
    payload: kalle kalas
    retain: false
  - name: sub meny name
    menu:
      - name: test 3
        topic: test
        payload: from submenu
        retain: false

logging

Configures the application logging, one or several logging destinations can be configuring and it's using the logging.config.dictConfig function

Plugin system

It's not much of a pluggin system, it's rough and ugly but anyways... The plugin should be put in the plugins subdirectory and the name of the directory will be the plugin name and the __init__.py in that directory will be called, eg plugins/myplugin/__init__.py When the application is launched it goes through all subscriptions in the mqtt section of the configuration file and checks for all plugins specified there. If the plugin configured in the configuration file and is present in the filesystem the plugin will be loaded.

One method is mandatory in the plugin and that's the prep method example for the notify plugin

def prep(msg=None, config=None):
    return_dict = {}
    return_dict['config'] = config
    icon = ICON
    if config is not None:
        if 'icon' in config:
            icon = config['icon']
    if msg is not None:
        return_dict['title'] = msg.topic
        return_dict['message'] = msg.payload
        return_dict['icon'] = icon
    return return_dict

When a topic that the application is subscribing to is updated the mqttclient will go though the plugin list defined for that topic and call the prep method with msg as parameter. msg.topic contains the topic thats been updated msg.payload contains the value thats been updated the prep should return a dictionary that will be used for the next step in the plugin, the method run

The run method is not mandatory, if the prep method is returning a runner key that contains the name of a plugin then that plugins run method will be used. the irssi plugin uses the notify run method

Here's a example of notify plugin beeing used:

notify

And here's a example of irssi plugin beeing used, using the notify runner

irssi

mqttclient's People

Contributors

swebarre avatar

Watchers

 avatar  avatar

mqttclient's Issues

Gdk-CRITICAL Error

getting a Gdk-CRITICAL **: gdk_window_thaw_toplevel_updates: assertion 'window->update_and_descendants_freeze_count > 0' failed when starting application

Create new config doesn't work

When launching the application without a ~/.mqttclient.yaml present the program crashes and throws the following error:

Traceback (most recent call last):
File "./mqttclient", line 358, in
CONFIG = read_config(CONFIG_FILE)
File "./mqttclient", line 313, in read_config
Gtk.DIALOG_DESTROY_WITH_PARENT,
File "/usr/lib64/python3.6/site-packages/gi/overrides/init.py", line 39, in getattr
return getattr(self._introspection_module, name)
File "/usr/lib64/python3.6/site-packages/gi/module.py", line 137, in getattr
self.name, name))
AttributeError: 'gi.repository.Gtk' object has no attribute 'DIALOG_DESTROY_WITH_PARENT'

A workaround is to manually copy the default_mqttclient.yaml to ~/.mqttclient.yaml and make your changes in that.

This function was missed when merging this pull request, #11

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.