functions and handling of stupid power values
Introduced PWRMAX als treshold for outgoing or incoming power. Before this sometimes useless values occured (e.g. 1000000 W for a normal family home). Introduced simple functions for the structure and error handling.
This commit is contained in:
parent
74240e8adf
commit
25504d0b68
26
edl21.sh
26
edl21.sh
@ -2,7 +2,7 @@
|
|||||||
# edl21.sh reads data from the EDL21 electricity meter and writes it up to a MySQL/MariaDB.
|
# edl21.sh reads data from the EDL21 electricity meter and writes it up to a MySQL/MariaDB.
|
||||||
# https://code.hw12.org/tilman/edl21
|
# https://code.hw12.org/tilman/edl21
|
||||||
#
|
#
|
||||||
# Version 0.5 - 03.03.2019
|
# Version 0.6 - 05.06.2019
|
||||||
#
|
#
|
||||||
# License GPL3.0 or later
|
# License GPL3.0 or later
|
||||||
# https://code.hw12.org/tilman/edl21/src/branch/master/LICENSE
|
# https://code.hw12.org/tilman/edl21/src/branch/master/LICENSE
|
||||||
@ -12,9 +12,9 @@ INPUT_DEV="/dev/ttyUSB0";
|
|||||||
stty -F $INPUT_DEV 1:0:8bd:0:3:1c:7f:15:4:5:1:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0
|
stty -F $INPUT_DEV 1:0:8bd:0:3:1c:7f:15:4:5:1:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0
|
||||||
|
|
||||||
#Log file and temporary txt.
|
#Log file and temporary txt.
|
||||||
|
PFAD=$(dirname "$(readlink -e "$0")");
|
||||||
FILE=$PFAD"/"$DATE."txt";
|
FILE=$PFAD"/"$DATE."txt";
|
||||||
LOG=$PFAD"/edl.log";
|
LOG=$PFAD"/edl.log";
|
||||||
PFAD=$(dirname "$(readlink -e "$0")");
|
|
||||||
|
|
||||||
#Database
|
#Database
|
||||||
DB_USER="dbuser";
|
DB_USER="dbuser";
|
||||||
@ -45,10 +45,13 @@ SEQ_180="070100010800FF";
|
|||||||
SEQ_280="070100020800FF";
|
SEQ_280="070100020800FF";
|
||||||
#Start of actual aktive power
|
#Start of actual aktive power
|
||||||
SEQ_PWR="070100100700FF";
|
SEQ_PWR="070100100700FF";
|
||||||
#Max possiple power value as mark of power direction
|
#Max possiple power value as mark of power direction (0x7FFFFFFF)
|
||||||
INOUT=2147483647;
|
INOUT=2147483647;
|
||||||
|
#Max useful power value for error handling (upper threshold in W)
|
||||||
|
PWRMAX=10000;
|
||||||
|
|
||||||
#Read from device
|
#Read from device
|
||||||
|
readNcalc() {
|
||||||
cat $INPUT_DEV 2>/dev/null | xxd -p -u -l 600 1> $FILE;
|
cat $INPUT_DEV 2>/dev/null | xxd -p -u -l 600 1> $FILE;
|
||||||
|
|
||||||
#Delete line breaks
|
#Delete line breaks
|
||||||
@ -70,19 +73,33 @@ let STRING_280=0x${STRING_280:20:10};
|
|||||||
STRING_PWR=${STRING#*$SEQ_PWR};
|
STRING_PWR=${STRING#*$SEQ_PWR};
|
||||||
let STRING_PWR=0x${STRING_PWR:14:8};
|
let STRING_PWR=0x${STRING_PWR:14:8};
|
||||||
|
|
||||||
|
checkNconvert;
|
||||||
|
}
|
||||||
|
|
||||||
|
checkNconvert() {
|
||||||
#Calculate direction of active power and convert in W (Watt)
|
#Calculate direction of active power and convert in W (Watt)
|
||||||
if [ $STRING_PWR -gt $INOUT ]; then
|
if [ $STRING_PWR -gt $INOUT ]; then
|
||||||
STRING_PWR_OUT=$(echo "(4294967295 - $STRING_PWR) / (10)"|bc);
|
STRING_PWR_OUT=$(echo "(4294967295 - $STRING_PWR) / (10)"|bc);
|
||||||
STRING_PWR_IN=0;
|
STRING_PWR_IN=0;
|
||||||
|
if [ $STRING_PWR_OUT -gt $PWRMAX ]; then
|
||||||
|
readNcalc;
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
STRING_PWR_IN=$(echo "$STRING_PWR / 10"|bc);
|
STRING_PWR_IN=$(echo "$STRING_PWR / 10"|bc);
|
||||||
STRING_PWR_OUT=0;
|
STRING_PWR_OUT=0;
|
||||||
|
if [ $STRING_PWR_IN -gt $PWRMAX ]; then
|
||||||
|
readNcalc;
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#Convert both active energy values in Wh (Watt hours)
|
#Convert both active energy values in Wh (Watt hours)
|
||||||
STRING_180=$(echo "scale=4; $STRING_180 / 10" |bc);
|
STRING_180=$(echo "scale=4; $STRING_180 / 10" |bc);
|
||||||
STRING_280=$(echo "scale=4; $STRING_280 / 10" |bc);
|
STRING_280=$(echo "scale=4; $STRING_280 / 10" |bc);
|
||||||
|
|
||||||
|
logNrock;
|
||||||
|
}
|
||||||
|
|
||||||
|
logNrock() {
|
||||||
#Write to log file
|
#Write to log file
|
||||||
echo $DATE";"$DATE_N5M";"$STRING_180";"$STRING_280";"$STRING_PWR_IN";"$STRING_PWR_OUT >> $LOG ;
|
echo $DATE";"$DATE_N5M";"$STRING_180";"$STRING_280";"$STRING_PWR_IN";"$STRING_PWR_OUT >> $LOG ;
|
||||||
|
|
||||||
@ -93,3 +110,6 @@ EOF
|
|||||||
|
|
||||||
#Delete temporary file
|
#Delete temporary file
|
||||||
rm $FILE;
|
rm $FILE;
|
||||||
|
}
|
||||||
|
|
||||||
|
readNcalc;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user