From c9b854a12364efdcfdf8ad2a80ef7b37a90b1013 Mon Sep 17 00:00:00 2001 From: Peter Molnar Date: Mon, 3 Dec 2018 10:22:08 +0000 Subject: [PATCH] i2cdetect instead of dmesg; minor cleanup --- _functions.sh | 7 ++----- iio-si1145.sh | 6 +++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/_functions.sh b/_functions.sh index bd03826..3356d45 100755 --- a/_functions.sh +++ b/_functions.sh @@ -7,7 +7,7 @@ MQTT_PORT="${COLLECTD_MQTTPORT:-1883}" MQTT_HOST="${COLLECTD_MQTTHOST:-$(hostname -f)}" MQTT_TOPIC="${COLLECTD_MQTTOPIC:-domoticz/in/MyMQTT}" -I2CBUS=$(dmesg | grep 'connected i2c-tiny-usb device' | head -n1 | sed -r 's/.*\s+i2c-([0-9]+).*/\1/') +I2CBUS=$(/usr/sbin/i2cdetect -l | grep i2c-tiny-usb | sed -r 's/^i2c-([0-9]+).*/\1/') S_DOOR=0 S_MOTION=1 @@ -110,7 +110,6 @@ function test_i2c_device { fi } - function humidity_to_comfort { hum=$(echo "scale=0;$1/1" | bc) @@ -130,7 +129,6 @@ function humidity_to_comfort { function domoticz_send { SEND="${1}" if nc -z ${HOSTNAME} ${DOMOTICZ_PORT}; then - #>&2 echo "sending to domoticz: ${SEND}" curl -s -H "Accept: application/json" "$SEND" >/dev/null else >&2 echo "domoticz can't be reaced at ${HOSTNAME} ${DOMOTICZ_PORT}" @@ -144,8 +142,7 @@ function mymqtt_test { fi if ! nc -z ${MQTT_HOST} ${MQTT_PORT}; then - >&2 echo "no MQTT available on ${MQTT_HOST}:${MQTT_PORT}" - exit 2 + exit 0 fi } diff --git a/iio-si1145.sh b/iio-si1145.sh index 9fcc507..9fefd99 100755 --- a/iio-si1145.sh +++ b/iio-si1145.sh @@ -23,14 +23,14 @@ while true; do fi prefix="sensors-weather" - suffix="-${sensorname}" + suffix="${sensorname}" declare -A data data[ir]=$(cat ${sensor}/in_intensity_ir_raw) - data[light]=$(cat ${sensor}/in_intensity_raw) + data[visible]=$(cat ${sensor}/in_intensity_raw) data[uv]=$(cat ${sensor}/in_uvindex_raw) for key in "${!data[@]}"; do - echo "PUTVAL $HOSTNAME/${prefix}/${key}${suffix} interval=$INTERVAL N:${data[$key]}" + echo "PUTVAL $HOSTNAME/${prefix}/gauge-${key}_${suffix} interval=$INTERVAL N:${data[$key]}" done mymqtt_update "${ID}" "${UV_ID}" "${V_UV}" "${data[uv]}"