Giter Club home page Giter Club logo

mqtt2notifysend's Introduction

MQTT2NotifySend

🌉Bridge between MQTT and 🖥️Freedesktop.org Notify-Send desktop notifications (Ubuntu & other distros)🐧, to send notifications to your desktop over MQTT.

Getting started

# Dependencies are: libnotify-bin, mosquitto-clients, jq, coreutils
sudo apt install libnotify-bin mosquitto-clients jq coreutils

# Download the script & set as executable (optional)
curl -O https://raw.githubusercontent.com/David-Lor/MQTT2NotifySend/master/mqtt2notifysend.sh
chmod u+x mqtt2notifysend.sh

# Run!
./mqtt2notifysend.sh -h localhost -t notifications

# Send a message to the broker from other terminal window
mosquitto_pub -h localhost -t notifications -m "{\"title\": \"Custom notification\", \"text\": \"Hello world\"}"
  • Script arguments for MQTT connection are the same used with the mosquitto_sub command (run ./mqt2notifysend.sh --help to know more).
  • The script expects a JSON string as payload, with the following tags:
    • title: notification title (optional)
    • text: notification body (required)
    • level: notification urgency level (optional; one of: low, normal, critical; default: normal)
    • iconB64: notification icon image, encoded as Base64 string (optional)

Environment variables

Certain settings can be tweaked using the following environment variables:

  • RECONNECTION_DELAY: time to wait between connection attempts, in seconds (default: 5)
  • DEFAULT_TITLE: default title for notifications sent without title (default: MQTT2NotifySend)
  • DEFAULT_LEVEL: default notify-send level for notifications sent without level (default: normal)
  • LOG_ENABLE: if true or 1, enable script logs (default: false)
  • ICON_BASE_PATH: where the notification icon file is downloaded, for each notification. This is an absolute/relative path of the file, used as prefix (default: /tmp/mqtt2notifysend-icon)
  • ICON_DELETE_DELAY: seconds to wait between the icon is decoded and deleted. Cannot be zero, as notifysend command may delay a bit and the icon may be removed when the notification pops up, not showing the icon (default: 5)

Usage:

LOG_ENABLE=true RECONNECTION_DELAY=1 DEFAULT_TITLE="Very important notification" DEFAULT_LEVEL=critical \
    bash mqtt2notifysend.sh -h localhost -t notifications

Changelog

  • 0.3.0 - Support sending icon for notifications, as base64-encoded string
  • 0.2.1 - Allow to disable logs; logs disabled by default; amends on script syntax; describe environment variables on README
  • 0.2.0 - Initial new Bash version from scratch
  • v0.1.0 - (Deprecated) Initial new version from scratch (branch python/develop)
  • v0.1 - (Deprecated) Initial version (branch python/master)

TODO

  • Support non-JSON payloads (only text and title-text split by delimiter)
  • Identify when mosquitto_sub fails due to connection error or user input (args) error
  • Validate dependencies installed before connecting
  • Support icons sent by URL

mqtt2notifysend's People

Contributors

david-lor avatar lodeiro0001 avatar zocker1999net avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mqtt2notifysend's Issues

Icon / Image for notification

Hello!
Just saw you mentioned potential upcoming support for icon.
Can you please also consider setting icon via a separate key having a base64 string value? Would be nice to be able to set e.g. a music cover image on sender and show it on desktop.
When using notify-send executable it's gonna be needed to temporary write the img to temporary file

So e.g. "icon" and "icon_base64" keys

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.