Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rtl4332mqtt : Named pipe instead of reconnects? #22

Open
rb2k opened this issue Jan 29, 2019 · 1 comment
Open

rtl4332mqtt : Named pipe instead of reconnects? #22

rb2k opened this issue Jan 29, 2019 · 1 comment

Comments

@rb2k
Copy link

rb2k commented Jan 29, 2019

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:

  1. Create a named pipe:
mkfifo /tmp/messages.pool
  1. 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 &
  1. 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?

@rb2k
Copy link
Author

rb2k commented Feb 2, 2019

I guess one problem I should mention: The custom channels disappear and the model name and id data ends up just in the payload.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant