From 28df0bd8eef991375b743b6e21110b3d0ea7efce Mon Sep 17 00:00:00 2001 From: Bogdan Vlaicu Date: Mon, 4 May 2020 20:15:49 -0400 Subject: [PATCH] New rtlamr addon --- rtlamr/config.json | 2 +- rtlamr/rtl2mqtt.sh | 40 +++++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/rtlamr/config.json b/rtlamr/config.json index a627f32..9c87dc4 100755 --- a/rtlamr/config.json +++ b/rtlamr/config.json @@ -1,6 +1,6 @@ { "name": "RTLAMR to MQTT Bridge", - "version": "0.0.2", + "version": "0.0.3", "slug": "rtlamr", "description": "RF to MQTT Bridge based on RTL_SDR/RTL_433 for RTL2832U based DVB-T USB tuners", "url": "https://github.com/bvlaicu/home-assistant-addons/tree/master/rtlamr", diff --git a/rtlamr/rtl2mqtt.sh b/rtlamr/rtl2mqtt.sh index b9d83c5..22e8fec 100755 --- a/rtlamr/rtl2mqtt.sh +++ b/rtlamr/rtl2mqtt.sh @@ -39,24 +39,30 @@ LASTVAL="0" # Do this loop, so will restart if buffer runs out while true; do -/go/bin/rtlamr -format json -msgtype=$MQTT_MSGTYPE -filterid=$MQTT_IDS | while read line -#/go/bin/rtlamr -format json -msgtype=$MQTT_MSGTYPE | while read line - -do - VAL="$(echo $line | jq --raw-output '.Message.Consumption' | tr -s ' ' '_')" # replace ' ' with '_' - DEVICEID="$(echo $line | jq --raw-output '.Message.ID' | tr -s ' ' '_')" - MSGTYPE="$(echo $line | jq --raw-output '.Type' | tr -s ' ' '_')" - MQTT_PATH="readings/$DEVICEID/meter_reading"a - - # Create file with touch /var/log/rtl_433.log if logging is needed - [ -w /var/log/rtl_433.log ] && echo $line >> /var/log/rtl_433.log - if [ "$VAL" != "$LASTVAL" ]; then - echo $VAL | /usr/bin/mosquitto_pub -h $MQTT_HOST -u $MQTT_USER -P $MQTT_PASS -i RTL_433 -r -l -t $MQTT_PATH - LASTVAL=$VAL + ID_FILTER_OPTION="" + if [ -z ${MQTT_IDS+x} ]; then + ID_FILTER_OPTION="" + else + ID_FILTER_OPTION=$MQTT_IDS fi - -done -sleep 60 + /go/bin/rtlamr -format json -msgtype=$MQTT_MSGTYPE $ID_FILTER_OPTION | while read line + + do + VAL="$(echo $line | jq --raw-output '.Message.Consumption' | tr -s ' ' '_')" # replace ' ' with '_' + DEVICEID="$(echo $line | jq --raw-output '.Message.ID' | tr -s ' ' '_')" + MSGTYPE="$(echo $line | jq --raw-output '.Type' | tr -s ' ' '_')" + MQTT_PATH="rtlamr/$DEVICEID/meter_reading" + + # Create file with touch /var/log/rtl_433.log if logging is needed + [ -w /var/log/rtl_433.log ] && echo $line >> /var/log/rtl_433.log + if [ "$VAL" != "$LASTVAL" ]; then + echo $VAL | /usr/bin/mosquitto_pub -h $MQTT_HOST -u $MQTT_USER -P $MQTT_PASS -i RTL_433 -r -l -t $MQTT_PATH + LASTVAL=$VAL + fi + + done + + sleep 60 done \ No newline at end of file