#!/bin/bash

# Umprogrammiertes wr_smartme modul 
. /var/www/html/openWB/openwb.conf

#Daten einlesen
wget http://$wr_smartme_user:$wr_smartme_pass@$wr_smartme_url -q -O /var/www/html/openWB/ramdisk/temppiko.txt

pvwatt=`/usr/bin/nawk 'BEGIN{
FS="<"
suchen = 0
}
{
if ( $1 ~ /aktuell/ ) {
suchen = 1
next
}
if ( ( suchen == 1 ) && ( $2 ~ /\/td/) ) {
suchen = 0
if ( $1 == "  x x x&nbsp" ) $1=0
printf "%s",$1
next
}
}' /var/www/html/openWB/ramdisk/temppiko.txt`

pvkwhk=`/usr/bin/nawk 'BEGIN{
FS="<"
suchen = 0
}
{
if ( $1 ~ /Gesamtenergie/ ) {
suchen = 1
next
}
if ( ( suchen == 1 ) && ( $2 ~ /\/td/) ) {
suchen = 0
printf "%s",$1
next
}
}' /var/www/html/openWB/ramdisk/temppiko.txt`

# PV Leistung muss negativ sein
pvwatt=$(echo "$pvwatt * -1" | bc)

#Ausgabe
echo $pvwatt
echo $pvwatt > /var/www/html/openWB/ramdisk/pvwatt

echo $pvkwhk > /var/www/html/openWB/ramdisk/pvkwhk

#Zählerstand Export (kWh --> Wh)
pvkwh=$(echo "scale=3 ; $pvkwhk * 1000" | bc)
echo $pvkwh > /var/www/html/openWB/ramdisk/pvkwh