Like I’ve mentioned before, I am using rtl_433 on my Raspberry Pi to receive the outside temperature and humidity from the sensor of my little weather station and store the values in a RRDtool database. Afterwards, I use the gathered data to make some graphs for different periods in the past.
In general, this works very well, but every now and then, after one or even after a couple of months, something in the RTL-SDR starts to hang, presumably the USB-controller itself, and you are only able to get it running again by disconnecting and reconnecting the stick physically. Least to say that I was not very happy with this circumstance, especially since I’ve tried different sticks, always with the same disappointing result. But like always, at least someone else was dealing with this kind of problem before and luckily already found a solution for it. The name of the solution is usbreset.c, a small C-program that can be build and used within just a few moments.
I am using a small Bash script to determine where the RTL-USB is located on the bus by using lsusb and to afterwards call the executable of usbreset.
#!/bin/bash USBNAME=RTL2838 LSUSB=$(lsusb | grep --ignore-case $USBNAME) DEVICE="/dev/bus/usb/"$(echo $LSUSB | cut --delimiter=' ' --fields='2')"/"$(echo $LSUSB | cut --delimiter=' ' --fields='4' | tr --delete ":") usbreset $DEVICE 2>&1 >/dev/null
Below is the Python script which I use for calling rtl_433. If everything went fine with the call, I write the received values to the database, otherwise I call the Bash script from above to force an USB reset of the RTL-SDR (instead of a physical reconnect).
#!/usr/bin/python import sys import os import rrdtool # read the current weather data process = os.popen('rtl_433 -g 42.1 -f 868250000 -q -R 8 -T 65') str = process.read() process.close() if not str: os.system('sudo ./reset_rtlsdr.sh') sys.exit(1) str = str.strip() str = str.replace('\t', '') str = str.replace('\n', ' ') data = str.split(' ') # check the order of the two messages and act accordingly if data == 'Temperature:' and data == 'Humidity:': update = 'N:' + data + ':' + data # insert data into database rrdtool.update("%s/weather.rrd" % (os.path.dirname(os.path.abspath(__file__))), update) elif data == 'Humidity:' and data == 'Temperature:': update = 'N:' + data + ':' + data # insert data into database rrdtool.update("%s/weather.rrd" % (os.path.dirname(os.path.abspath(__file__))), update)