hassio-addons
hassio-addons copied to clipboard
rtl4332mqtt : Named pipe instead of reconnects?
The addon currently uses this combination to send each line to mqtt:
/usr/local/bin/rtl_433 -F json -R $PROTOCOL -f $FREQUENCY -g $GAIN -p $OFFSET | while read line
[...]
echo $line | /usr/bin/mosquitto_pub [...]
This works but causes a fork/exec on every single line that comes in.
My local script is heavily hacked modified, but basically I changed the script a bit to use this methodology:
- Create a named pipe:
mkfifo /tmp/messages.pool
- Fork off a process that tails the pipe and a mosquitto one that reads from it For the 'cat 0<> ' see https://unix.stackexchange.com/questions/392697/reading-a-named-pipe-tail-or-cat
function start_tailing() {
cat 0<> /tmp/messages | /usr/bin/mosquitto_pub -h $MQTT_HOST -u $MQTT_USER -P $MQTT_PASS -i RTL_433 -r -l -t $MQTT_TOPIC
}
start_tailing &
- The blocking thing that iterates over each line and ultimately writes to the pipe:
echo $line > /tmp/messages.pool
That way we only fork/exec the mosquitto_pub process once rather than on every single line that comes in.
What do you think about that approach?
I guess one problem I should mention: The custom channels disappear and the model name and id data ends up just in the payload.