should be working now

This commit is contained in:
Florian Klemenz 2024-10-20 09:01:31 +02:00
parent 1ae30d5d91
commit 0eefa1772a
4 changed files with 32 additions and 31 deletions

View File

@ -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)
IFS=$'\n'
SENSORS=( $(eval $CMD) )
SENSORS+=("${s} ${v}")
done
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"

View File

@ -1,5 +1,5 @@
#!/bin/bash
# -*- sh -*-
# -*- bash -*-
: << =cut

View File

@ -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)

View File

@ -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