From c6bc47e7f108760a9681534ab3b5940e4bd2f93a Mon Sep 17 00:00:00 2001 From: Bogdan Vlaicu Date: Thu, 7 May 2020 17:38:06 -0400 Subject: [PATCH] rtlamr fix for missing meter ids --- rtlamr/config.json | 2 +- rtlamr/run.sh | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/rtlamr/config.json b/rtlamr/config.json index 94a4f6d..4be675f 100755 --- a/rtlamr/config.json +++ b/rtlamr/config.json @@ -1,6 +1,6 @@ { "name": "RTLAMR to MQTT Bridge", - "version": "0.1.11", + "version": "0.1.12", "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/run.sh b/rtlamr/run.sh index bca6cf0..aa9add7 100755 --- a/rtlamr/run.sh +++ b/rtlamr/run.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash export LANG=C PATH="/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin" @@ -11,8 +11,8 @@ CONFIG_PATH=/data/options.json MQTT_HOST="$(jq --raw-output '.mqtt_host' $CONFIG_PATH)" MQTT_USER="$(jq --raw-output '.mqtt_user' $CONFIG_PATH)" MQTT_PASS="$(jq --raw-output '.mqtt_password' $CONFIG_PATH)" -MQTT_MSGTYPE="$(jq --raw-output '.msg_type' $CONFIG_PATH)" -MQTT_IDS="$(jq --raw-output '.meter_ids' $CONFIG_PATH)" +MSG_TYPE="$(jq --raw-output '.msg_type' $CONFIG_PATH)" +METER_IDS="$(jq --raw-output '.meter_ids // empty' $CONFIG_PATH)" # Start the listener and enter an endless loop @@ -21,8 +21,8 @@ echo "MQTT Host =" $MQTT_HOST echo "MQTT User =" $MQTT_USER #MQTT_PASS_REDACTED=$(sed 's/^......./*******/' <<<$MQTT_PASS) #echo "MQTT Password =" $MQTT_PASS_REDACTED -echo "Message Type =" $MQTT_MSGTYPE -echo "Meter IDs =" $MQTT_IDS +echo "Message Type =" $MSG_TYPE +echo "Meter IDs =" $METER_IDS #set -x ## uncomment for MQTT logging... @@ -37,16 +37,16 @@ LASTVAL="0" #tail -f /dev/null + +if [ -z ${METER_IDS+x} ] || [${METER_IDS} = ""]; then + ID_FILTER_OPTION="" +else + ID_FILTER_OPTION="-filterid=$METER_IDS" +fi + # Do this loop, so will restart if buffer runs out while true; do - - if [[ -z ${MQTT_IDS+x} ] || [${MQTT_IDS} = ""] || [${MQTT_IDS} = "null"]]; then - ID_FILTER_OPTION="" - else - ID_FILTER_OPTION="-filterid=$MQTT_IDS" - fi - - /go/bin/rtlamr -format json -msgtype=$MQTT_MSGTYPE $ID_FILTER_OPTION | while read line + /go/bin/rtlamr -format json -msgtype=$MSG_TYPE $ID_FILTER_OPTION | while read line do VAL="$(echo $line | jq --raw-output '.Message.Consumption' | tr -s ' ' '_')" # replace ' ' with '_'