Git Product home page Git Product logo

janvda / balena-python-evdev2mqtt Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 1.0 1.19 MB

This is a Balena application mainly consisting of a micro service (docker container) that is listening to key events (press/hold/release) of an USB device (e.g. keypad, keyboard,…) connected to a raspberry pi and publishing those events as MQTT messages.

License: Eclipse Public License 2.0

Python 25.54% Dockerfile 9.73% JavaScript 64.72%
balena-application python-evdev raspberry-pi node-red mqtt balenacloud balena docker docker-compose keyboard

balena-python-evdev2mqtt's Introduction

Balena "python-evdev2mqtt" Application

This is a Balena application consisting of 3 docker containers.

  1. python-evdev2mqtt: this service is sending an mqtt message whenever a key is pressed/hold/released for a specific input device connected to one of the USB ports of a raspberry pi.
  2. mqtt : mqtt broker receiving the mqtt messages sent by the python-evdev2mqtt service.
  3. node-red: this service has a dual purpose:
    1. It demonstrates that python-evdev2mqttis working properly as it outputs those mqtt messages in the debug window of the node-red editor.
    2. It also demonstrates the (limited) features of the node-red-contrib-usbhid nodes that can also be used to receive events from those input devices connected to the USB ports of a raspberry pi.

Rationale for this Application

The idea is to create a micro service (= python-evdev2mqtt) that sends MQTT messages whenever a keyevent happens on an input device connected to a USB port of a raspberry pi device. Other services (e.g. node-red) by listening to those mqtt messages could then respond appropriately.

E.g. a numeric USB keypad can then be used to control the volume, switch radio channels, pauze, ...

Additional Features

  1. Node-red editor can be accessed through the public device URL from the BalenaCloud dashboard.
  2. It is also easy to create a hashed password for node-red by running the command "node-red-admin hash-pw" in a terminal window for the node-red service.

Hardware needed besides a raspberry pi

  1. You need an USB device that generates key events (e.g. keypad, keyboard, ...)

SETUP INSTRUCTIONS

1. Deploy Balena application

So as you might have guessed this is indeed a balena application. So follow all standard instructions for setting up and deploying this balena application. (e.g. see Get started with Raspberry Pi 3 and Python and its github repository) After this step this balena application should be running on your raspberry pi.

2. TBD

3. Set Device Service Variables for the python-evdev2mqtt service

Within your balenacloud dashboard you can set the following device service variables for the python-evdev2mqtt container.

Service Variable Description
input_device This is the path of the input device that is connected to one of the USB ports of the raspberry pi. E.g. /dev/input/event1. Note that mqtt messages will only be sent for key events of this input device. At startup of the python-evdev2mqtt service all the connected input devices (with path) are written to the logs which you can view in the BalenaCloud dashboard.
mqtt_broker default value = mqtt. This variable must be set if you want to use a different mqtt broker instead of the mqtt service
mqtt_port default value = 1883. If the mqtt broker is listening to a different port then this variable must be set.

Interesting Links

  1. python-evdev
  2. python-evdev package also comes with a small command-line program for listing and monitoring input devices:

python -m evdev.evtest

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.