diff --git a/scripts/plugins/1wire b/scripts/plugins/1wire index 8a99f74..cd652d1 100755 --- a/scripts/plugins/1wire +++ b/scripts/plugins/1wire @@ -1,11 +1,11 @@ #!/bin/bash -# -*- sh -*- +# -*- bash -*- : << =cut =head1 NAME -433mhz - Plugin to capture readings from wireless sensors via serial +1wire - Plugin to capture readings from 1wire sensors on raspberry pi =head1 NOTES @@ -32,8 +32,7 @@ if [ "$1" = "autoconf" ]; then fi if [ "$1" = "config" ]; then - - echo 'graph_title Wireless temperature sensor readings' + echo 'graph_title 1wire sensor readings' echo 'graph_args --base 1 -l 0 ' echo 'graph_scale no' echo 'graph_vlabel °C' @@ -45,19 +44,22 @@ if [ "$1" = "config" ]; then exit 0 fi +SENSORS=() -CMD="for f in $(find -L /sys/bus/w1/devices/ -maxdepth 2 -name temperature); do s=${f%/*}; s=${s##*-}; v=$(cat $f); echo "${s} ${v}"; done" +FILES=$(find -L /sys/bus/w1/devices/ -maxdepth 2 -name temperature) +for f in $FILES +do + s=${f%/*} + s=${s##*-} + v=$(cat $f) + + SENSORS+=("${s} ${v}") +done -IFS=$'\n' -SENSORS=( $(eval $CMD) ) - -echo $SENSORS - -IFS=' ' for ROW in "${SENSORS[@]}"; do ENTRY=( $ROW ) SENSOR=${ENTRY[0]} - VALUE=${ENTRY[1]} + VALUE=${ENTRY[1]/#[0-9][0-9]/&.} # Overrides SENSOR - Example: env.sensor_0_0 Batterie ENV_SENSOR_VAR_NAME="alias_${SENSOR}" @@ -69,7 +71,3 @@ for ROW in "${SENSORS[@]}"; do echo "${SENSOR}.value ${VALUE}" fi done - - -#echo "Vorratskammer.value $TEMP" - diff --git a/scripts/plugins/433mhz b/scripts/plugins/433mhz index be2f1d8..8ad59d9 100755 --- a/scripts/plugins/433mhz +++ b/scripts/plugins/433mhz @@ -1,5 +1,5 @@ #!/bin/bash -# -*- sh -*- +# -*- bash -*- : << =cut diff --git a/scripts/plugins/ina219 b/scripts/plugins/ina219 index ccb1f9d..60ac957 100755 --- a/scripts/plugins/ina219 +++ b/scripts/plugins/ina219 @@ -1,5 +1,5 @@ -#!/bin/sh -# -*- sh -*- +#!/bin/bash +# -*- bash -*- : << =cut @@ -32,7 +32,6 @@ if [ "$1" = "autoconf" ]; then fi if [ "$1" = "config" ]; then - echo 'graph_title Power' echo 'graph_args --base 1 -l 0 ' echo 'graph_scale no' @@ -45,22 +44,26 @@ if [ "$1" = "config" ]; then exit 0 fi -ROUNDS=5 +ROUNDS=3 VOLTAGE=0 CURRENT=0 POWER=0 for i in $(seq ${ROUNDS}); do - RESULT=$(/usr/bin/ina219) + #ROW="12204mV 184.3mA" + ROW=$(/usr/bin/ina219) + ENTRY=( $ROW ) + + VOLTAGE_RAW=${ENTRY[0]%mV} + CURRENT_RAW=${ENTRY[1]%mA} + #echo "Voltage: ${VOLTAGE_RAW}" + #echo "Current: ${CURRENT_RAW}" - VOLTAGE_RAW=$(echo $RESULT | /bin/sed 's/\([0-9]\+\)mV \+\([0-9\.]\+\)mA/\1/') VOLTAGE=$(echo "scale=3; $VOLTAGE+$VOLTAGE_RAW" | /usr/bin/bc) - - CURRENT_RAW=$(echo $RESULT | /bin/sed 's/\([0-9]\+\)mV \+\([0-9\.]\+\)mA/\2/') CURRENT=$(echo "scale=3; $CURRENT+$CURRENT_RAW" | /usr/bin/bc) - done +#exit 1 VOLTAGE=$(echo "scale=3; $VOLTAGE/$ROUNDS" | /usr/bin/bc) CURRENT=$(echo "scale=3; $CURRENT/$ROUNDS" | /usr/bin/bc) diff --git a/scripts/run.sh b/scripts/run.sh index 5e86a41..080eec3 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -2,8 +2,8 @@ source ~/.mysql-grafana.conf -PLUGINS="1wire 433mhz" -#PLUGINS="433mhz ina219" +PLUGINS="1wire 433mhz ina219" +#PLUGINS="433mhz" # https://stackoverflow.com/a/1482133 SCRIPT_PATH=$(dirname -- "$( readlink -f -- "$0"; )";) @@ -29,7 +29,7 @@ for PLUGIN in ${PLUGINS}; do echo "${PLUGIN_ENV}" fi - DATA=$(env -i ${PLUGIN_ENV} plugins/${PLUGIN} | tail -n +2 | head -n -1) + DATA=$(env -i ${PLUGIN_ENV} plugins/${PLUGIN}) echo "-----------------" echo "$DATA" @@ -44,8 +44,8 @@ for PLUGIN in ${PLUGINS}; do #echo $LINE SQL=$(echo $LINE | sed -E "s/(.*)\.(.*) (.*)/INSERT INTO ${TABLE_NAME} (source, metric, value) VALUES (\"${SOURCE}\",\"\1\", \"\3\");/") - echo $SQL - #echo $SQL | mysql --host="192.168.0.12" --database="${DATABASE}" --user="${USER}" --password="${PASSWORD}" + #echo $SQL + echo $SQL | mysql --host="192.168.0.12" --database="${DATABASE}" --user="${USER}" --password="${PASSWORD}" done # LINE done # PLUGINS