lektor January & February 2021 29
Search in this list for a line like this:
Bus 001 Device 008: ID 0bda:2838 Realtek
Semiconductor Corp. RTL2838 DVB-T
Note the bus and device number: 001 and 008. Now look at the
device files for the bus 001:
ls -l /dev/bus/usb/001
You should see a line like this:
crw-rw---- 1 pi root 189, 10 May 7 20:22 008
This shows that the device is owned by the user pi, which has read
and write permissions.
After this, create the container with:
docker-compose up -d
After the container has been created, look at its logs:
docker logs -f rtl433tomqtt
As shown in Figure 4, you should see some messages that the
rtl_433 program is trying to find a configuration file in a few places,
that is has registered more than 120 decoding protocols, and that
is has found a receiver device. Then you should see a message
‘Tuned to 433.920MHz’ and if all goes well you should now see
sensor values coming in. Have some patience, because many of
these sensors only transmit once a minute.
Configuring rtl_433
In the beginning of the logs, you saw that rtl_433 tried to find some
configuration files. It didn’t find one, so it just used a default configu-
Any Realtek RTL2832 based DVB dongle should work with rtl_433,
including the official RTL-SDR dongle. I’m using the RTL-SDR
dongle with a dipole antenna from the RTL-SDR antenna kit. Just
connect the antenna to the RTL-SDR and put the RTL-SDR in a USB
port of your Raspberry Pi.
Warning: The RTL-SDR produces quite a lot heat while it’s running.
Take care of where you position it.
Installing rtl_433toMQTT
The rtl_433 program is actively developed and maintained and has
more than 150 protocol decoders for various devices that trans-
mit on 433.92 MHz. Moreover, it can send the received values to
an MQTT broker. Luckily, someone created a Docker container
with rtl_433 for this exact purpose (https://github.com/bademux/
rtl_433toMQTT) [3].
First, create a directory for the container:
mkdir -p /home/pi/containers/rtl433tomqtt
Then add the container definition to your docker-compose.yml file:
version: ‘3.7’
services:
mosquitto:
mosquitto config
rtl433tomqtt:
image: bademux/rtl_433tomqtt:latest
container_name: rtl433tomqtt
restart: always
volumes:
- ./containers/rtl433tomqtt:/home/user/.config/
rtl_433:ro - /etc/localtime:/etc/localtime:ro
devices: - /dev/bus/usb:/dev/bus/usb
Enter the configuration of the Docker container for Mosquitto
instead of ‘#mosquitto config’. The container needs access to
the USB bus to read from the RTL-SDR device. Note also that the
directory you created is mounted as a volume. You don’t have to
create a configuration file yet.
First create a udev rule to give the right permissions to the USB
device:
sudo nano /etc/udev/rules.d/20.rtl-sdr.rules
Enter the following line:
SUBSYSTEM=="usb", ATTRS{idVendor}=="0bda", ATTRS{idPr
oduct}=="2838",OWNER="pi", MODE="0660"
Save the file with Ctrl+o and exit nano with Ctrl+x. Then unplug
the RTL-SDR and reattach it. Now look at the list of attached USB
devices:
lsusb
Figure 4: The rtl_433 command automatically finds the RTL-SDR receiver
and starts showing received sensor readings.