Difference between revisions of "Volkszähler"
Jump to navigation
Jump to search
Line 13: | Line 13: | ||
</source> | </source> | ||
= Test USB S0 reader = | = Test USB S0 reader = | ||
+ | == readmeter == | ||
+ | <source lang='bash'> | ||
+ | #!/bin/bash | ||
+ | # read and evaluate SML output received from EMH eHZ | ||
+ | |||
+ | getmeter() { | ||
+ | # set serial device | ||
+ | INPUT_DEV="/dev/ttyUSB0" | ||
+ | |||
+ | #set $INPUT_DEV to 9600 8N1 | ||
+ | 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 | ||
+ | |||
+ | SML_START_SEQUENCE="1B1B1B1B0101010176" | ||
+ | METER_OUTPUT__START_SEQUENCE="" | ||
+ | |||
+ | while [ "$METER_OUTPUT__START_SEQUENCE" != "$SML_START_SEQUENCE" ] | ||
+ | do | ||
+ | METER_OUTPUT=`cat $INPUT_DEV 2>/dev/null | xxd -p -u -l 460 | tr -d '[:space:]'` | ||
+ | METER_OUTPUT__START_SEQUENCE=$(echo "${METER_OUTPUT:0:18}") | ||
+ | if [ "$METER_OUTPUT__START_SEQUENCE" != "$SML_START_SEQUENCE" ]; | ||
+ | then | ||
+ | echo "missed start and trying again..." | ||
+ | sleep 0.1 | ||
+ | #exit 1 | ||
+ | fi | ||
+ | done | ||
+ | |||
+ | echo $METER_OUTPUT | ||
+ | } | ||
+ | |||
+ | # | ||
+ | # match | ||
+ | # 1: prefix | ||
+ | # 2: text | ||
+ | # 3: ofs | ||
+ | # 4: len | ||
+ | # | ||
+ | matchvalue() { | ||
+ | local l_prefix="$1" | ||
+ | local l_text="$2" | ||
+ | local l_ofs="$3" | ||
+ | local l_len="$4" | ||
+ | local l_prefix_len=${#l_prefix} | ||
+ | local l_text_len=${#l_text} | ||
+ | local l_start=0 | ||
+ | let l_max=l_text_len-l_prefix_len | ||
+ | #echo "$l_prefix_len - $l_text_len - $l_max" | ||
+ | while [ $l_start -lt $l_max ] | ||
+ | do | ||
+ | l_part=${l_text:$l_start:$l_prefix_len} | ||
+ | if [ "$l_prefix" = "$l_part" ] | ||
+ | then | ||
+ | let l_start=l_start+l_prefix_len+l_ofs | ||
+ | local l_value_hex=${l_text:$l_start:$l_len} | ||
+ | let l_value=0x${l_value_hex} | ||
+ | #echo ${l_start} | ||
+ | #echo ${l_value_hex} | ||
+ | echo $l_value | ||
+ | return | ||
+ | fi | ||
+ | let l_start=l_start+1 | ||
+ | done | ||
+ | } | ||
+ | |||
+ | # | ||
+ | # get a value from the SML Sequence | ||
+ | # | ||
+ | getvalue() { | ||
+ | local l_prefix="$1" | ||
+ | local l_text="$2" | ||
+ | local l_ofs="$3" | ||
+ | local l_len="$4" | ||
+ | local l_factor="$5" | ||
+ | local l_title="$6" | ||
+ | local l_unit="$7" | ||
+ | echo "$l_title" "$l_unit" | ||
+ | #echo "ofs:$l_ofs len: $l_len factor: $l_factor" | ||
+ | matchvalue "$l_prefix" "$l_text" "$l_ofs" "$l_len" | ||
+ | #echo $METER_180 | ||
+ | #VALUE=$(echo "scale=2; $METER_180 / $l_factor" |bc) | ||
+ | } | ||
+ | |||
+ | echo "SML SEQUENCE:" | ||
+ | getmeter | ||
+ | getvalue "77070100010800FF" "$METER_OUTPUT" 20 8 10000 "Meter 1.8.0 (from plant):" "kWh" | ||
+ | getvalue "77070100020800FF" "$METER_OUTPUT" 20 8 10000 " Meter 2.8.0 (to plant):" "kWh" | ||
+ | getvalue "77070100010801FF" "$METER_OUTPUT" 20 8 10 "1.8.1" "kW" | ||
+ | getvalue "77070100010802FF" "$METER_OUTPUT" 20 8 10 "1.8.2" "kW" | ||
+ | getvalue "77070100020801FF" "$METER_OUTPUT" 20 8 10 "2.8.1" "kW" | ||
+ | getvalue "77070100020802FF" "$METER_OUTPUT" 20 8 10 "2.8.2" "kW" | ||
+ | </source> |
Revision as of 13:36, 27 July 2019
- https://www.volkszaehler.org/
- https://wiki.volkszaehler.org/software/releases/start
- https://wiki.volkszaehler.org/howto/raspberry_pi_image
- https://wiki.volkszaehler.org/hardware/channels/meters/power/edl-ehz/edl21-ehz
- https://wiki.volkszaehler.org/hardware/controllers/ir-schreib-lesekopf?s[]=ir&s[]=lesekopf
- https://wiki.volkszaehler.org/hardware/controllers/ir-schreib-lesekopf-usb-ausgang
Install desktop
If you'd like to have the desktop configuration for the raspberry that you configured using the Volkzsähler image you can install the desktop with:
sudo apt-get install raspberrypi-ui-mods -y
sudo raspi-config # activate desktop via menu
Test USB S0 reader
readmeter
#!/bin/bash
# read and evaluate SML output received from EMH eHZ
getmeter() {
# set serial device
INPUT_DEV="/dev/ttyUSB0"
#set $INPUT_DEV to 9600 8N1
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
SML_START_SEQUENCE="1B1B1B1B0101010176"
METER_OUTPUT__START_SEQUENCE=""
while [ "$METER_OUTPUT__START_SEQUENCE" != "$SML_START_SEQUENCE" ]
do
METER_OUTPUT=`cat $INPUT_DEV 2>/dev/null | xxd -p -u -l 460 | tr -d '[:space:]'`
METER_OUTPUT__START_SEQUENCE=$(echo "${METER_OUTPUT:0:18}")
if [ "$METER_OUTPUT__START_SEQUENCE" != "$SML_START_SEQUENCE" ];
then
echo "missed start and trying again..."
sleep 0.1
#exit 1
fi
done
echo $METER_OUTPUT
}
#
# match
# 1: prefix
# 2: text
# 3: ofs
# 4: len
#
matchvalue() {
local l_prefix="$1"
local l_text="$2"
local l_ofs="$3"
local l_len="$4"
local l_prefix_len=${#l_prefix}
local l_text_len=${#l_text}
local l_start=0
let l_max=l_text_len-l_prefix_len
#echo "$l_prefix_len - $l_text_len - $l_max"
while [ $l_start -lt $l_max ]
do
l_part=${l_text:$l_start:$l_prefix_len}
if [ "$l_prefix" = "$l_part" ]
then
let l_start=l_start+l_prefix_len+l_ofs
local l_value_hex=${l_text:$l_start:$l_len}
let l_value=0x${l_value_hex}
#echo ${l_start}
#echo ${l_value_hex}
echo $l_value
return
fi
let l_start=l_start+1
done
}
#
# get a value from the SML Sequence
#
getvalue() {
local l_prefix="$1"
local l_text="$2"
local l_ofs="$3"
local l_len="$4"
local l_factor="$5"
local l_title="$6"
local l_unit="$7"
echo "$l_title" "$l_unit"
#echo "ofs:$l_ofs len: $l_len factor: $l_factor"
matchvalue "$l_prefix" "$l_text" "$l_ofs" "$l_len"
#echo $METER_180
#VALUE=$(echo "scale=2; $METER_180 / $l_factor" |bc)
}
echo "SML SEQUENCE:"
getmeter
getvalue "77070100010800FF" "$METER_OUTPUT" 20 8 10000 "Meter 1.8.0 (from plant):" "kWh"
getvalue "77070100020800FF" "$METER_OUTPUT" 20 8 10000 " Meter 2.8.0 (to plant):" "kWh"
getvalue "77070100010801FF" "$METER_OUTPUT" 20 8 10 "1.8.1" "kW"
getvalue "77070100010802FF" "$METER_OUTPUT" 20 8 10 "1.8.2" "kW"
getvalue "77070100020801FF" "$METER_OUTPUT" 20 8 10 "2.8.1" "kW"
getvalue "77070100020802FF" "$METER_OUTPUT" 20 8 10 "2.8.2" "kW"