Compare commits

..

4 Commits
0.5 ... master

Author SHA1 Message Date
c0dcb44009 „edldata.sql“ ändern
Tabelle für Snapshot und Tageswerte hinzugefügt.
2020-04-16 20:42:27 +02:00
353661ecf5 „edl21.sh“ ändern
Upload in Snapshot-Tabelle hinzugefügt - schnelleres Auslesen durch Webseite möglich.
2020-04-16 20:35:55 +02:00
25504d0b68 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.
2019-06-05 21:23:11 +02:00
74240e8adf „README.md“ ändern 2019-03-03 21:15:45 +01:00
3 changed files with 76 additions and 11 deletions

View File

@ -2,3 +2,11 @@
Dieses Script ruft mittels optischem Lesekopf die Daten vom Stromzähler Typ EDL21 ab und überträgt sie in eine MySQL/MariaDB-Datenbank von wo aus sie beliebig weiterverarbeitet werden können (z.B. [pChart](https://github.com/bozhinov/pChart2.0-for-PHP7)).
Es findet kein CRC-Check statt!
### Hintergrundwissen
http://wiki.volkszaehler.org/hardware/channels/meters/power/edl-ehz/edl21-ehz
http://blog.bubux.de/tag/stromzaehler/ (Vielen Dank!)

View File

@ -2,8 +2,6 @@
# edl21.sh reads data from the EDL21 electricity meter and writes it up to a MySQL/MariaDB.
# https://code.hw12.org/tilman/edl21
#
# Version 0.5 - 03.03.2019
#
# License GPL3.0 or later
# https://code.hw12.org/tilman/edl21/src/branch/master/LICENSE
@ -12,16 +10,17 @@ 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
#Log file and temporary txt.
PFAD=$(dirname "$(readlink -e "$0")");
FILE=$PFAD"/"$DATE."txt";
LOG=$PFAD"/edl.log";
PFAD=$(dirname "$(readlink -e "$0")");
#Database
DB_USER="dbuser";
DB_PASS="dbpasswd";
DB_HOST="dbhost";
DB_NAME="dbname";
DB_TAB="dbtable";
DB_TAB="EdlData";
DB_TAB_SNAP="EdlSnapshot";
#Get date and round to nearest 5min (for harmonized use with data from other scripts in pChart)
DATE_RAW=$(/bin/date +%s);
@ -45,10 +44,13 @@ SEQ_180="070100010800FF";
SEQ_280="070100020800FF";
#Start of actual aktive power
SEQ_PWR="070100100700FF";
#Max possiple power value as mark of power direction
#Max possiple power value as mark of power direction (0x7FFFFFFF)
INOUT=2147483647;
#Max useful power value for error handling (upper threshold in W)
PWRMAX=10000;
#Read from device
readNcalc() {
cat $INPUT_DEV 2>/dev/null | xxd -p -u -l 600 1> $FILE;
#Delete line breaks
@ -70,26 +72,44 @@ let STRING_280=0x${STRING_280:20:10};
STRING_PWR=${STRING#*$SEQ_PWR};
let STRING_PWR=0x${STRING_PWR:14:8};
checkNconvert;
}
checkNconvert() {
#Calculate direction of active power and convert in W (Watt)
if [ $STRING_PWR -gt $INOUT ]; then
STRING_PWR_OUT=$(echo "(4294967295 - $STRING_PWR) / (10)"|bc);
STRING_PWR_IN=0;
if [ $STRING_PWR_OUT -gt $PWRMAX ]; then
readNcalc;
fi
else
STRING_PWR_IN=$(echo "$STRING_PWR / 10"|bc);
STRING_PWR_OUT=0;
if [ $STRING_PWR_IN -gt $PWRMAX ]; then
readNcalc;
fi
fi
#Convert both active energy values in Wh (Watt hours)
STRING_180=$(echo "scale=4; $STRING_180 / 10" |bc);
STRING_280=$(echo "scale=4; $STRING_280 / 10" |bc);
logNrock;
}
logNrock() {
#Write to log file
echo $DATE";"$DATE_N5M";"$STRING_180";"$STRING_280";"$STRING_PWR_IN";"$STRING_PWR_OUT >> $LOG ;
#Send data to database
mysql -u $DB_USER -p$DB_PASS -h $DB_HOST -D $DB_NAME <<EOF
INSERT INTO $DB_TAB (TimeStamp,Nearest5min,zaehlerstand_in,zaehlerstand_out,active_in,active_out) VALUES ('$DATE','$DATE_N5M','$STRING_180','$STRING_280','$STRING_PWR_IN','$STRING_PWR_OUT');
INSERT INTO $DB_TAB (TimeStamp,Nearest5min,zaehlerstand_in,zaehlerstand_out,active_in,active_out) VALUES ('${DATE}','${DATE_N5M}','${STRING_180}','${STRING_280}','${STRING_PWR_IN}','${STRING_PWR_OUT}');
UPDATE $DB_TAB_SNAP SET TimeStamp='${DATE}',Nearest5min='${DATE_N5M}',zaehlerstand_in='${STRING_180}',zaehlerstand_out='${STRING_280}',active_in='${STRING_PWR_IN}',active_out='${STRING_PWR_OUT}';
EOF
#Delete temporary file
rm $FILE;
}
readNcalc;

View File

@ -1,3 +1,17 @@
--
-- Tabellenstruktur für Tabelle `DayData`
--
CREATE TABLE `DayData` (
`TimeStamp` datetime NOT NULL,
`zaehlerstand_in` float NOT NULL,
`zaehlerstand_out` float NOT NULL,
`active_in` float NOT NULL,
`active_out` float NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `EdlData`
--
@ -11,17 +25,40 @@ CREATE TABLE `EdlData` (
`active_out` float NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `EdlSnapshot`
--
CREATE TABLE `EdlSnapshot` (
`TimeStamp` datetime NOT NULL,
`Nearest5min` datetime NOT NULL,
`zaehlerstand_in` float NOT NULL,
`zaehlerstand_out` float NOT NULL,
`active_in` float NOT NULL,
`active_out` float NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Indizes der exportierten Tabellen
--
--
-- Indizes für die Tabelle `DayData`
--
ALTER TABLE `DayData`
ADD KEY `TimeStamp` (`TimeStamp`);
--
-- Indizes für die Tabelle `EdlData`
--
ALTER TABLE `EdlData`
ADD UNIQUE KEY `TimeStamp` (`TimeStamp`);
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
--
-- Indizes für die Tabelle `EdlSnapshot`
--
ALTER TABLE `EdlSnapshot`
ADD UNIQUE KEY `TimeStamp` (`TimeStamp`);
COMMIT;