2019/08/18

RaspberryPi rtl_433 to MQTT gateway

Parts list:

  1. RasberryPi Zero W (and optional case)
  2. Micro SD card
  3. any USB power supply and micro USB cable
  4. RTL2838U DVB USB tuner with an external antenna

First get the RaspberryPi running:

  1. Download the latest Raspbian Lite OS image
  2. Flash the Raspbian image to your SD card with Etcher
  3. Enable WiFi and SSH on your SD card before putting it in the Pi

    mount the SD card on your computer

    Enable SSH:

    cd /Volumes/boot/ && touch ssh

    Setup WiFi:

    echo "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    country=us
    network={
        ssid=\"YOUR_SSID\"
        psk=\"YOUR_WIFI_PASSWORD\"
        key_mgmt=WPA-PSK
    }
    " >> wpa_supplicant.conf
  4. Eject the SD card, put it in the RaspberryPi, and boot the Pi.

Find the Pi's IP address and ssh to it.
arp -a
nmap -p 22 --open -sV 192.168.1.0/24

ssh pi@IPADDRESS
default password is "raspberry"

sudo raspi-config
expand the file system to use the whole SD card space - should happen automatically on first boot

change the password or use ssh-copy-id setup access

upgrade the software:
sudo apt-get update -y && sudo apt-get dist-upgrade -y && sudo apt-get autoremove -y

Now your RaspberryPi has a base OS that is ready to setup for whatever work you want it to do. In this case I want it to run the rtl_433 software to capture wireless temerature sensor data and send it to my MQTT server.

Setup the rtl_433 software

Here is a great guide to setting up and running the rtl_433 software: http://www.sensorsiot.org/install-rtl_433-for-a-sdr-rtl-dongle-on-a-raspberry-pi/

I have Acurite sensors and want to see the temperature in Fahrenheit so I used " -R 40 -R 41 -C customary" in my config file.

This shows how I'm running the software:

pi@raspberrypi:~ $ cat /etc/supervisor/conf.d/rtl_433.conf

[program:rtl_433]
command=/home/pi/rtl_433/build/src/rtl_433 -R 40 -R 41 -C customary -F "mqtt://YOUR_MQTT_SERVER:1883,,user=YOUR_MQTT_USERNAME,pass=YOUR_MQTT_PASSWORD,events=YOUR_MQTT_TOPIC"
user=pi
autostart=yes
autorestart=yes
startretries=100
stderr_logfile=/var/log/rtl_433/rtl_433.err.log
stdout_logfile=/var/log/rtl_433/rtl_433.log



That's it! Now just plug it in somewhere that it can recieve the 433Mhz signals and connect to the Wifi. You should start getting the temperature data on your MQTT topic.

No comments: