Skip to content

Commit

Permalink
modbus evse DIN implementiert, SDM Abfrage umgebaut
Browse files Browse the repository at this point in the history
  • Loading branch information
snaptec committed Mar 23, 2018
1 parent bdf9b45 commit 33962d8
Show file tree
Hide file tree
Showing 50 changed files with 254 additions and 106 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ ausführen.




In der Shell folgendes eingeben:

curl -s https://raw.githubusercontent.com/snaptec/openWB/master/openwb-install.sh | sudo sh
Expand Down Expand Up @@ -146,8 +147,7 @@ aufrufen

# Danke geht an:

Frank für das Bereitstellen von Hardware
Frank für das Bereitstellen von Hardware und sein Modbus Wissen!


Gonium für sein super Tool zum auslesen der SDM: https://github.com/gonium/gosdm630

51 changes: 35 additions & 16 deletions modules/sdm630modbusbezug/main.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,45 @@
#!/bin/bash

###############
#SDM630v2 wird mithilfe von https://github.com/gonium/gosdm630 ausgelesen.
#auch für SDM230 nutzbar (L2 und L3 bleiben dann immer 0
#bezug = bezug soll Modbus ID 2 sein
. /var/www/html/openWB/openwb.conf

#check ob gonium reader lauft
if ps ax |grep -v grep |grep "sdm630_httpd-linux-arm -s $sdm630modbusbezugsource -d SDM:$sdm630modbusbezugid -u $sdm630modbusbezugport" > /dev/null
if [[ $sdm630modbusbezugsource = *virtual* ]]
then
else
sudo /home/pi/bin/sdm630_httpd-linux-arm -s $sdm630modbusbezugsource -d SDM:$sdm630modbusbezugid -u $sdm630modbusbezugport &
if ps ax |grep -v grep |grep "socat pty,link=$sdm630modbusbezugsource,raw tcp:$sdm630modbusbezuglanip:26" > /dev/null
then
echo "test" > /dev/null
else
sudo socat pty,link=$sdm630modbusbezugsource,raw tcp:$sdm630modbusbezuglanip:26 &
fi
else
echo "echo" > /dev/null
fi

bezuga1=$(curl -s localhost:8080/last/$sdm630modbusbezugid |jq '.Current.L1' | tr -d '\n' | sed 's/\..*$//')
bezuga2=$(curl -s localhost:8080/last/$sdm630modbusbezugid |jq '.Current.L2' | tr -d '\n' | sed 's/\..*$//')
bezuga3=$(curl -s localhost:8080/last/$sdm630modbusbezugid |jq '.Current.L3' | tr -d '\n' | sed 's/\..*$//')
wattbezug=`curl -s localhost:8080/last/$sdm630modbusbezugid |jq '.Power.L1' | tr -d '\n' | sed 's/\..*$//'`
n=0
output=$(sudo python /var/www/html/openWB/modules/sdm630modbusbezug/readsdm.py $sdm630modbusbezugsource $sdm630modbusbezugid)
while read -r line; do
if (( $n == 0 )); then
echo "$line" | cut -c2- |sed 's/\..*$//' > /var/www/html/openWB/ramdisk/bezuga1
fi
if (( $n == 1 )); then
echo "$line" | cut -c2- |sed 's/\..*$//' > /var/www/html/openWB/ramdisk/bezuga2
fi
if (( $n == 2 )); then
echo "$line" | cut -c2- |sed 's/\..*$//' > /var/www/html/openWB/ramdisk/bezuga3
fi
if (( $n == 3 )); then
wl1=$(echo "$line" | cut -c2- |sed 's/\..*$//')
fi
if (( $n == 4 )); then
wl2=$(echo "$line" | cut -c2- |sed 's/\..*$//')
fi
if (( $n == 5 )); then
wl3=$(echo "$line" | cut -c2- |sed 's/\..*$//')
fi

n=$((n + 1))
done <<< "$output"

wattbezug=`echo "($wl1+wl2+$wl3)" |bc`
echo $wattbezug > /var/www/html/openWB/ramdisk/wattbezug
echo $bezuga1 > /var/www/html/openWB/ramdisk/bezuga1
echo $bezuga2 > /var/www/html/openWB/ramdisk/bezuga2
echo $bezuga3 > /var/www/html/openWB/ramdisk/bezuga3



33 changes: 33 additions & 0 deletions modules/sdm630modbusbezug/readsdm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/python
import sys
import os
import time
import getopt
import socket
import ConfigParser
import struct
import binascii
seradd = str(sys.argv[1])
from pymodbus.client.sync import ModbusSerialClient
client = ModbusSerialClient(method = "rtu", port=seradd, baudrate=9600,
stopbits=1, bytesize=8, timeout=1)

#rq = client.read_holding_registers(0,8,unit=5)
#print(rq.registers)
sdmid = int(sys.argv[2])

resp = client.read_input_registers(0x06,2, unit=sdmid)

print(struct.unpack('>f',struct.pack('>HH',*resp.registers)))
resp = client.read_input_registers(0x08,2, unit=sdmid)
print(struct.unpack('>f',struct.pack('>HH',*resp.registers)))
resp = client.read_input_registers(0x0A,2, unit=sdmid)
print(struct.unpack('>f',struct.pack('>HH',*resp.registers)))

resp = client.read_input_registers(0x0C,2, unit=sdmid)
print(struct.unpack('>f',struct.pack('>HH',*resp.registers)))
resp = client.read_input_registers(0x0E,2, unit=sdmid)
print(struct.unpack('>f',struct.pack('>HH',*resp.registers)))
resp = client.read_input_registers(0x10,2, unit=sdmid)
print(struct.unpack('>f',struct.pack('>HH',*resp.registers)))

47 changes: 18 additions & 29 deletions modules/sdm630modbusll/main.sh
Original file line number Diff line number Diff line change
@@ -1,45 +1,34 @@
#!/bin/bash

###############
#SDM630v2 wird mithilfe von https://github.com/gonium/gosdm630 ausgelesen.
#auch für SDM230 nutzbar (L2 und L3 bleiben dann immer 0
#ll = ladeleistung soll Modbus ID 1 sein
# Gonium Tool fragt standard nur ID1 ab

. /var/www/html/openWB/openwb.conf


if [[ $sdm630modbusllsource = *virtual* ]]
then
if ps ax |grep -v grep |grep "socat pty,link=$sdm630modbusllsource,raw tcp:$sdm630modbuslllanip:26" > /dev/null
then
echo "test" > /dev/null
else
sudo socat pty,link=$sdm630modbusllsource,raw tcp:$sdm630modbuslllanip:26
sudo socat pty,link=$sdm630modbusllsource,raw tcp:$sdm630modbuslllanip:26 &
fi
else
echo "echo" > /dev/null
fi
n=0
output=$(sudo python /var/www/html/openWB/modules/sdm630modbusll/readsdm.py $sdm630modbusllsource $sdm630modbusllid)
while read -r line; do


#check ob gonium reader lauft
if ps ax |grep -v grep |grep "sdm630_httpd-linux-arm -s $sdm630modbusllsource -d SDM:$sdm630modbusllid -u $sdm630modbusllport" > /dev/null
then
echo "test" > /dev/null
else
sudo /home/pi/bin/sdm630_httpd-linux-arm -s $sdm630modbusllsource -d SDM:$sdm630modbusllid -u $sdm630modbusllport &
if (( $n == 0 )); then
echo "$line" | cut -c2- |sed 's/\..*$//' > /var/www/html/openWB/ramdisk/lla1
fi
if (( $n == 1 )); then
echo "$line" | cut -c2- |sed 's/\..*$//' > /var/www/html/openWB/ramdisk/lla2
fi
if (( $n == 2 )); then
echo "$line" | cut -c2- |sed 's/\..*$//' > /var/www/html/openWB/ramdisk/lla3
fi
if (( $n == 3 )); then
echo "$line" | cut -c2- |sed 's/\..*$//' > /var/www/html/openWB/ramdisk/llaktuell
fi
n=$((n + 1))
done <<< "$output"


lla1=$(curl -s localhost:8080/last/$sdm630modbusllid |jq '.Current.L1' | tr -d '\n' | sed 's/\..*$//')
lla2=$(curl -s localhost:8080/last/$sdm630modbusllid |jq '.Current.L2' | tr -d '\n' | sed 's/\..*$//')
lla3=$(curl -s localhost:8080/last/$sdm630modbusllid |jq '.Current.L3' | tr -d '\n' | sed 's/\..*$//')
ladeleistung=`curl -s localhost:8080/last/$sdm630modbusllid |jq '.Power.L1' | tr -d '\n' | sed 's/\..*$//'`


echo $ladeleistung > /var/www/html/openWB/ramdisk/llaktuell
echo $lla1 > /var/www/html/openWB/ramdisk/lla1
echo $lla2 > /var/www/html/openWB/ramdisk/lla2
echo $lla3 > /var/www/html/openWB/ramdisk/lla3

wattbezugint=0

30 changes: 30 additions & 0 deletions modules/sdm630modbusll/readsdm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/python
import sys
import os
import time
import getopt
import socket
import ConfigParser
import struct
import binascii
seradd = str(sys.argv[1])
from pymodbus.client.sync import ModbusSerialClient
client = ModbusSerialClient(method = "rtu", port=seradd, baudrate=9600,
stopbits=1, bytesize=8, timeout=1)

#rq = client.read_holding_registers(0,8,unit=5)
#print(rq.registers)
sdmid = int(sys.argv[2])

resp = client.read_input_registers(0x06,2, unit=sdmid)

print(struct.unpack('>f',struct.pack('>HH',*resp.registers)))
resp = client.read_input_registers(0x08,2, unit=sdmid)
print(struct.unpack('>f',struct.pack('>HH',*resp.registers)))
resp = client.read_input_registers(0x0A,2, unit=sdmid)
print(struct.unpack('>f',struct.pack('>HH',*resp.registers)))

resp = client.read_input_registers(0x0C,2, unit=sdmid)
print(struct.unpack('>f',struct.pack('>HH',*resp.registers)))


9 changes: 1 addition & 8 deletions openwb-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,6 @@ else
echo "...ok"
fi

echo "check for gonium/sdm630"
if [ ! -d /home/pi/bin ]; then
wget https://github.com/gonium/gosdm630/releases/download/v0.5.0/sdm630-linux-arm.zip
unzip sdm630-linux-arm.zip
echo "... installed"
else
echo "...ok"
fi

echo "check for socat"
if ! [ -x "$(command -v socat)" ]; then
Expand All @@ -143,6 +135,7 @@ then
else
echo "EXTRA_OPTS="-L 0"" >> /etc/default/cron
fi
sudo pip install -U pymodbus

chmod 777 /var/www/html/openWB/openwb.conf
chmod +x /var/www/html/openWB/modules/*
Expand Down
13 changes: 5 additions & 8 deletions openwb.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ debug=0

#Minimal mögliche Ladeleistung in A(nur höher Stellen wenn das Fahrzeug Probleme bereitet)
#Einstellbar von 6-10
minimalstromstaerke=6
minimalstromstaerke=16

#Maximal erlaubte Ladeleistung in A. Als Beispiel: 16A entspricht einphasig 3,6kw, 3-phasig 11kw, Abhängig von genutzter Verkabelung (Querschnitt) etc..
#Einstellbar von 10-32
Expand Down Expand Up @@ -42,12 +42,11 @@ vzloggerip=10.20.0.51:8080

#Einstellungen für Modul sdm630modbusbezug
# Modbus ID des sdm
sdm630modbusbezugid=1
sdm630modbusbezugid=5
# Serieller Port. Bei USB-RS485 Adapter meist /dev/tty/USB0
sdm630modbusbezugsource=/dev/virtualcom0
sdm630modbusbezugsource=/dev/virtualcom1
# Port lokal für für das gonium tool. Darf sich nicht mit anderen Gonium Instanzen ueberschneiden.
sdm630modbusbezugport=:8081

sdm630modbusbezuglanip=10.20.0.180



Expand All @@ -74,8 +73,6 @@ sdm630modbusllid=1
# Serieller Port. Bei USB-RS485 Adapter meist /dev/tty/USB0
#fuer Verbindungen ueber Lan Konverter muss die source /dev/virtualcomX (0,1,usw..) sein
sdm630modbusllsource=/dev/ttyUSB0
# Port lokal für für das gonium tool. Darf sich nicht mit anderen Gonium Instanzen ueberschneiden, werden alle in dieser conf festgelegt.
sdm630modbusllport=:8080
#bei Verbindung über Lan Konverter
sdm630modbuslllanip=10.20.0.180
#beim Wechsel von source einstellungen oder von ttyUSB auf virtualcom0 ist ein neustart des raspberry erforderlich.
Expand Down Expand Up @@ -125,4 +122,4 @@ abschaltuberschuss=900

# Der Modi Sofort Laden lädt immer mit der vorgegebenen Ladeleistung
# Mögliche Werte: 6-32 (A)
sofortll=16
sofortll=20
1 change: 1 addition & 0 deletions ramdisk/bezuga1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
1 change: 1 addition & 0 deletions ramdisk/bezuga2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
1 change: 1 addition & 0 deletions ramdisk/bezuga3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
2 changes: 1 addition & 1 deletion ramdisk/lademodus
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0
1
2 changes: 1 addition & 1 deletion ramdisk/lla1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0
16
2 changes: 1 addition & 1 deletion ramdisk/llaktuell
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0
3678
2 changes: 1 addition & 1 deletion ramdisk/pvwatt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0
1032
2 changes: 1 addition & 1 deletion ramdisk/soc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
33
87
2 changes: 1 addition & 1 deletion ramdisk/wattbezug
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1391
4529
12 changes: 8 additions & 4 deletions regel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cd /var/www/html/openWB/

#Wattbezug
if [[ $wattbezugmodul != "none" ]]; then
wattbezug=`modules/$wattbezugmodul/main.sh`
wattbezug=`timeout 10 modules/$wattbezugmodul/main.sh`
#uberschuss zur berechnung
wattbezugint=`printf "%.0f\n" $wattbezug`
uberschuss=`expr $wattbezugint \* -1`
Expand All @@ -22,14 +22,14 @@ fi

#PV Leistung ermitteln
if [[ $pvwattmodul != "none" ]]; then
pvwatt=`modules/$pvwattmodul/main.sh`
pvwatt=`timeout 10 modules/$pvwattmodul/main.sh`
if [[ $debug == "1" ]]; then
echo pvwatt $pvwatt
fi
fi
#Ladeleistung ermitteln
if [[ $ladeleistungmodul != "none" ]]; then
modules/$ladeleistungmodul/main.sh
timeout 10 modules/$ladeleistungmodul/main.sh
lla1=$(cat /var/www/html/openWB/ramdisk/lla1)
lla2=$(cat /var/www/html/openWB/ramdisk/lla2)
lla3=$(cat /var/www/html/openWB/ramdisk/lla3)
Expand Down Expand Up @@ -202,7 +202,11 @@ if grep -q 1 "/var/www/html/openWB/ramdisk/lademodus"; then
fi
exit 0
else
exit 0
if (( $llalt < $minimalstromstaerke )); then
llneu=$((llalt + 1 ))
runs/$llneu.sh
fi
exit 0
fi
fi
if (( $uberschuss > $schaltschwelle )); then
Expand Down
4 changes: 4 additions & 0 deletions runs/0.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
if [[ $evsecon == "dac" ]]; then
sudo python /var/www/html/openWB/runs/dac.py 0 $dacregister
fi
if [[ $evsecon == "modbusevse" ]]; then
sudo python /var/www/html/openWB/runs/evsewritemodbus.py $modbusevsesource $modbusevseid 0
fi

if [[ $debug == "2" ]]; then
echo "setz ladung auf 0A" >> /var/www/html/openWB/web/lade.log
fi
Expand Down
3 changes: 3 additions & 0 deletions runs/10.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
if [[ $evsecon == "dac" ]]; then
sudo python /var/www/html/openWB/runs/dac.py 1298 $dacregister
fi
if [[ $evsecon == "modbusevse" ]]; then
sudo python /var/www/html/openWB/runs/evsewritemodbus.py $modbusevsesource $modbusevseid 10
fi
if [[ $debug == "2" ]]; then
echo "setz ladung auf 10A" >> /var/www/html/openWB/web/lade.log
fi
Expand Down
3 changes: 3 additions & 0 deletions runs/11.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
if [[ $evsecon == "dac" ]]; then
sudo python /var/www/html/openWB/runs/dac.py 1427 $dacregister
fi
if [[ $evsecon == "modbusevse" ]]; then
sudo python /var/www/html/openWB/runs/evsewritemodbus.py $modbusevsesource $modbusevseid 11
fi
if [[ $debug == "2" ]]; then
echo "setz ladung auf 11A" >> /var/www/html/openWB/web/lade.log
fi
Expand Down
3 changes: 3 additions & 0 deletions runs/12.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
if [[ $evsecon == "dac" ]]; then
sudo python /var/www/html/openWB/runs/dac.py 1557 $dacregister
fi
if [[ $evsecon == "modbusevse" ]]; then
sudo python /var/www/html/openWB/runs/evsewritemodbus.py $modbusevsesource $modbusevseid 12
fi
if [[ $debug == "2" ]]; then
echo "setz ladung auf 12A" >> /var/www/html/openWB/web/lade.log
fi
Expand Down
3 changes: 3 additions & 0 deletions runs/13.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
if [[ $evsecon == "dac" ]]; then
sudo python /var/www/html/openWB/runs/dac.py 1687 $dacregister
fi
if [[ $evsecon == "modbusevse" ]]; then
sudo python /var/www/html/openWB/runs/evsewritemodbus.py $modbusevsesource $modbusevseid 13
fi
if [[ $debug == "2" ]]; then
echo "setz ladung auf 13A" >> /var/www/html/openWB/web/lade.log
fi
Expand Down
3 changes: 3 additions & 0 deletions runs/14.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
if [[ $evsecon == "dac" ]]; then
sudo python /var/www/html/openWB/runs/dac.py 1814 $dacregister
fi
if [[ $evsecon == "modbusevse" ]]; then
sudo python /var/www/html/openWB/runs/evsewritemodbus.py $modbusevsesource $modbusevseid 14
fi
if [[ $debug == "2" ]]; then
echo "setz ladung auf 14A" >> /var/www/html/openWB/web/lade.log
fi
Expand Down
Loading

0 comments on commit 33962d8

Please sign in to comment.