This is a Balena application consisting of 3 docker containers.
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.mqtt
: mqtt broker receiving the mqtt messages sent by thepython-evdev2mqtt
service.node-red
: this service has a dual purpose:- It demonstrates that
python-evdev2mqtt
is working properly as it outputs those mqtt messages in the debug window of the node-red editor. - 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.
- It demonstrates that
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, ...
- Node-red editor can be accessed through the public device URL from the BalenaCloud dashboard.
- 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 thenode-red
service.
- You need an USB device that generates key events (e.g. keypad, keyboard, ...)
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.
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. |
- python-evdev
- python-evdev package also comes with a small command-line program for listing and monitoring input devices:
python -m evdev.evtest