MQTT System Tray Icon
This project provides a small python script which builds system tray icons from messages on MQTT subscribtions. The icons are build combining SVG template files and the jinja2 template processor to render images depending on the MQTT message payload. The payload needs to be JSON encoded.
I developed mqttstray to get the measurements of my CGM to my GNU/Linux desktop. See also the xDrip+ example.
# clone the repository
git clone https://github.com/liske/mqttstray.git
# create python virtual env
cd mqttstray && virtualenv -p python3 .venv
# enter virtual env and install missing dependencies
. .venv/bin/activate
pip install -r requirements.txt
The main configuration file is ${XDG_CONFIG_HOME}/mqttstray/config
.
The configuration file requires to contain a section for the MQTT connection:
[_MQTT]
host=127.0.0.1
port=8883
tls=True
verify=False
username=joe
password=foobar
The following settings are supported for the MQTT constructor and MQTT connect invocation:
host
- the host used for the MQTT connectionport
- the port used for the MQTT connection (default:1883
)client_id
- unique client id (default:${USER}@$(hostname -f)
)transport
- tcp or websockets MQTT transport (default:tcp
)username
- MQTT authentication username (default: None)password
- MQTT authentication password (default: None)
The following settings are supported for the MQTT tls_set invocation:
tls
- enable TLS for the MQTT connection (default:False
)verify
- verify the MQTT broker's X.509 certificate (default:True
)ca_certs
- pathname for the CA files (default: system's CA list is used)certfile
- client certificate file used for authentication (default: None)keyfile
- client private key file used for authentication (default: None)ciphers
- restrict allowed encryption ciphers or use python's defaultinsecure
- ignore MQTT broker's X.509 certificate subject hostname (default:False
)
Any other section not beginning with a underscore (_
) is handled as an icon configuration:
[xDrip mmol/l]
topic=android/broadcast/my-phone/xdrip
filename=xDrip/icon-mmol.svg
outdated=600
An icon section has the following options:
topic
- a single MQTT topic used for this iconfilename
- SVG filename to be used as jinja2 template to render the final icon
Example icons can be found in the ex/ directory.
- no support for wildcard topics(, yet)
- currently only one topic per icon is supported
- only a connection to a single MQTT broker is supported
- MQTT payload requires to be JSON encoded