Skip to content

Commit

Permalink
Merge pull request #11 from jjk4/dev
Browse files Browse the repository at this point in the history
V1.1
  • Loading branch information
jjk4 authored Jun 20, 2021
2 parents c570b5c + 49af8bf commit 4083b67
Show file tree
Hide file tree
Showing 32 changed files with 204 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Notizzettel.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Python Skripte werden aufgerufen mit:
python3 file.py host port datenbank zaehler
python3 file.py host port datenbank benutzer passwort zaehler

Haupt Datenbank in dev Datenbank kopieren:
DROP DATABASE energietest
Expand Down
4 changes: 3 additions & 1 deletion add_values.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
$config = json_decode(file_get_contents('config.json'), true);
$host = $config['host'];
$port = $config['port'];
$username = $config['username'];
$password = $config['password'];
$database = $config['database'];
foreach ($config['zaehler'] as $key => $value) {
exec ("python3 add_values.py $host $port $database $key");
exec ("python3 add_values.py $host $port $database $username $password $key");
};
?>
4 changes: 2 additions & 2 deletions add_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
#command = "touch \"" + str(sys.argv) + "\""
#os.system(command)
maxdays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
client = InfluxDBClient(host=str(sys.argv[1]), port=int(sys.argv[2]))
client = InfluxDBClient(host=str(sys.argv[1]), port=int(sys.argv[2]), username=str(sys.argv[4]), password=str(sys.argv[5]))
client.switch_database(str(sys.argv[3]))

database = str(sys.argv[4])
database = str(sys.argv[6])

month = 1
year = 2015
Expand Down
1 change: 1 addition & 0 deletions app/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<title><?=$site_name?> - Energiezählerapp</title>
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<script src="jquery.js"></script>


</head>
Expand Down
4 changes: 3 additions & 1 deletion app/submitinput.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
$database = $config['database'];
$host = $config['host'];
$port = $config['port'];
$username = $config['username'];
$password = $config['password'];
$zaehler = $_GET["zaehler"];
$datum = $_GET["datum"];
$wert = $_GET["wert"];
exec ("python3 ../input.py $host $port $database $zaehler $datum $wert", $output);
exec ("python3 ../input.py $host $port $database $username $password $zaehler $datum $wert", $output);
?>
</body>
</html>
4 changes: 3 additions & 1 deletion app/submitquery.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
$database = $config['database'];
$host = $config['host'];
$port = $config['port'];
$username = $config['username'];
$password = $config['password'];
$zaehler = $_GET["zaehler"];
$startdatum = $_GET["startdatum"] . ":00Z";
$enddatum = $_GET["enddatum"] . ":00Z";
echo shell_exec("python3 ../query.py $host $port $database $zaehler $startdatum $enddatum");
echo shell_exec("python3 ../query.py $host $port $database $username $password $zaehler $startdatum $enddatum");
?>
</div>
</body>
Expand Down
1 change: 1 addition & 0 deletions app/visu/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<link rel="stylesheet" href="../style.css">
<link rel="icon" href="../../favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<script src="jquery.js"></script>
</head>
<body>
<h2><?=$site_name?> - Energiezähler</h2>
Expand Down
6 changes: 3 additions & 3 deletions app/visu/months.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from influxdb import InfluxDBClient
import datetime

client = InfluxDBClient(host=str(sys.argv[1]), port=int(sys.argv[2]))
client = InfluxDBClient(host=str(sys.argv[1]), port=int(sys.argv[2]), username=str(sys.argv[4]), password=str(sys.argv[5]))
client.switch_database(str(sys.argv[3]))

dt = datetime.datetime.today()
maxdays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
database = str(sys.argv[5])
year = sys.argv[4]
database = str(sys.argv[7])
year = sys.argv[6]
month = 1
all_values = []

Expand Down
4 changes: 3 additions & 1 deletion app/visu/months_submit.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
$database = $config['database'];
$host = $config['host'];
$port = $config['port'];
$username = $config['username'];
$password = $config['password'];
$zaehler = $_GET["database"];
?>
<a href="index.php">Zurück</a>
Expand All @@ -16,7 +18,7 @@
<?php
for ($i = 1; $i <= $_GET["number"]; $i++) {
$year = $_GET["year$i"];
$command = escapeshellcmd('python3 months.py ' . " " . $host . " " . $port . " " . $database . " " . $year . " " . $zaehler);
$command = escapeshellcmd('python3 months.py ' . " " . $host . " " . $port . " " . $database . " " . $username . " " . $password . " " . $year . " " . $zaehler);
$output = shell_exec($command);
$arr = json_decode($output, true);
echo "{
Expand Down
6 changes: 3 additions & 3 deletions app/visu/years.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
from influxdb import InfluxDBClient
import datetime

client = InfluxDBClient(host=str(sys.argv[1]), port=int(sys.argv[2]))
client = InfluxDBClient(host=str(sys.argv[1]), port=int(sys.argv[2]), username=str(sys.argv[4]), password=str(sys.argv[5]))
client.switch_database(str(sys.argv[3]))

database = str(sys.argv[5])
year = sys.argv[4]
database = str(sys.argv[7])
year = sys.argv[6]

results = client.query("SELECT FIRST(value) FROM " + database + " WHERE time >= '" + str(year) + "-01-01T00:00:00Z' and time <= '" + str(year) + "-12-31T23:59:59Z' tz('Europe/Berlin')")
points = results.get_points
Expand Down
4 changes: 3 additions & 1 deletion app/visu/years_submit.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
$database = $config['database'];
$host = $config['host'];
$port = $config['port'];
$username = $config['username'];
$password = $config['password'];
$zaehler = $_GET["database"];
?>
<a href="index.php">Zurück</a>
Expand All @@ -19,7 +21,7 @@
<?php
for ($i = 1; $i <= $_GET["number"]; $i++) {
$year = $_GET["year$i"];
$command = escapeshellcmd('python3 years.py ' . " " . $host . " " . $port . " " . $database . " " . $year . " " . $zaehler);
$command = escapeshellcmd('python3 years.py ' . " " . $host . " " . $port . " " . $database . " " . $username . " " . $password . " " . $year . " " . $zaehler);
$output = shell_exec($command);
$values .= $output . ", ";
}
Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"host":"192.168.178.198","port":"8086","database":"energietest","zaehler":{"pv_garage":{"displayname":"PV Garage","unit":"kWh","type":"manual"},"wasser":{"displayname":"Wasser","unit":"m\u00b3","type":"manual"},"strom":{"displayname":"Strom","unit":"kWh","type":"manual"},"heizung":{"displayname":"Heizung","unit":"kWh","type":"manual"},"garten":{"displayname":"Garten","unit":"kWh","type":"manual"},"lueftung_heizraum":{"displayname":"L\u00fcftung Heizraum","unit":"kWh","type":"manual"},"display_flur":{"displayname":"Display Flur","unit":"kWh","type":"manual"},"pv_haus":{"displayname":"PV Haus","unit":"kWh","type":"manual"}}}
{"host":"192.168.178.198","port":"8086","username":"None","password":"None","database":"energietest","installationpath":"\/var\/www\/energie","zaehler":{"pv_garage":{"displayname":"PV Garage","unit":"kWh","type":"manual","sdm630_usb":"","sdm630_id":"","sdm630_counter":"l1"},"wasser":{"displayname":"Wasser","unit":"m\u00b3","type":"manual","sdm630_usb":"","sdm630_id":"","sdm630_counter":"l1"},"strom":{"displayname":"Strom","unit":"kWh","type":"manual","sdm630_usb":"","sdm630_id":"","sdm630_counter":"l1"},"heizung":{"displayname":"Heizung","unit":"kWh","type":"manual","sdm630_usb":"","sdm630_id":"","sdm630_counter":"l1"},"garten":{"displayname":"Garten","unit":"kWh","type":"manual","sdm630_usb":"","sdm630_id":"","sdm630_counter":"l1"},"lueftung_heizraum":{"displayname":"L\u00fcftung Heizraum","unit":"kWh","type":"manual","sdm630_usb":"","sdm630_id":"","sdm630_counter":"l1"},"display_flur":{"displayname":"Display Flur","unit":"kWh","type":"manual","sdm630_usb":"","sdm630_id":"","sdm630_counter":"l1"},"pv_haus":{"displayname":"PV Haus","unit":"kWh","type":"manual","sdm630_usb":"","sdm630_id":"","sdm630_counter":"all"},"heizung_modbus":{"displayname":"Heizung Modbus","unit":"kWh","type":"sdm630","sdm630_usb":"\/dev\/ttyUSB0","sdm630_id":"1","sdm630_counter":"all"}}}
63 changes: 60 additions & 3 deletions configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
<label>Datenbank
<input name="database" type="text" placeholder="Datenbank" value="<?php echo($config['database']);?>">
</label><br><br>
<label>Benutzername
<input name="username" type="text" placeholder="Benutzername" value="<?php echo($config['username']);?>">
</label><br><br>
<label>Passwort
<input name="password" type="password" placeholder="Passwort" value="<?php echo($config['password']);?>">
</label><br><br>
<h3>Energiezählereinstellungen</h3>
<label>Installationspfad
<input name="installationpath" type="text" placeholder="Installationspfad" value="<?php echo($config['installationpath']);?>">
</label><br><br>
<h3>Zählereinstellungen</h3>
<table border="1">
<tr>
Expand All @@ -31,6 +41,10 @@
foreach ($config['zaehler'] as $key => $value) {
$displayname = $value['displayname'];
$unit = $value['unit'];
$type = $value['type'];
$sdm630_usb = $value['sdm630_usb'];
$sdm630_id = $value['sdm630_id'];
$sdm630_counter = $value['sdm630_counter'];
echo "
<tr>
<td>
Expand All @@ -43,9 +57,27 @@
<input name=\"" . $key . "_unit\" type=\"text\" value=\"$unit\">
</td>
<td>
<select name=\"" . $key . "_type\">
<option value=\"manual\">Manuelle Eingabe</option>
<select name=\"" . $key . "_type\" id=\"" . $key . "_type\">
<option value=\"manual\""; if ($type == "manual") {echo(" selected ");}; echo ">Manuelle Eingabe</option>
<option value=\"sdm630\""; if ($type == "sdm630") {echo(" selected ");}; echo ">SDM630 Modbus</option>
</select>
<div class=\"" . $key . "_sdm630\">
<label>USB Schnittstelle<br>
<input name=\"" . $key . "_sdm630_usb\" type=\"text\" value=\"$sdm630_usb\">
</label><br>
<label>Modbus ID<br>
<input name=\"" . $key . "_sdm630_id\" type=\"number\" value=\"$sdm630_id\">
</label><br>
<label>Zähler<br>
<select name=\"" . $key . "_sdm630_counter\">
<option value=\"l1\""; if ($sdm630_counter == "l1") {echo(" selected ");}; echo ">L1</option>
<option value=\"l2\""; if ($sdm630_counter == "l2") {echo(" selected ");}; echo ">L2</option>
<option value=\"l3\""; if ($sdm630_counter == "l3") {echo(" selected ");}; echo ">L3</option>
<option value=\"all\""; if ($sdm630_counter == "all") {echo(" selected ");}; echo ">Gesamt</option>
</select>
</label><br>
</div>
</td>
<td>
<input type=\"checkbox\"name=\"" . $key . "_delete\">
Expand All @@ -66,7 +98,32 @@
function addCounter() {
document.getElementById("neu").style.display = 'block';
document.getElementById("add").style.display = 'none';
}
};
$( document ).ready(function() {
<?php
foreach ($config['zaehler'] as $key => $value) {
echo "
if (document.getElementById('" . $key . "_type').value == 'sdm630'){
$(\"." . $key . "_sdm630\").show();
} else if (this.value == 'manual'){
$(\"." . $key . "_sdm630\").hide();
}";
}
?>
});
<?php
foreach ($config['zaehler'] as $key => $value) {
echo "$(\"." . $key . "_sdm630\").hide();
let sel_" . $key . " = document.getElementById('" . $key . "_type');
sel_" . $key . ".addEventListener ('change', function () {
if (this.value == 'sdm630'){
$(\"." . $key . "_sdm630\").show();
} else if (this.value == 'manual'){
$(\"." . $key . "_sdm630\").hide();
}
});";
}
?>
</script>
</body>
</html>
1 change: 1 addition & 0 deletions downloads/config-2021-06-20_10:13.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"host":"192.168.178.198","port":"8086","username":"None","password":"None","database":"energietest","installationpath":"\/var\/www\/energie","zaehler":{"pv_garage":{"displayname":"PV Garage","unit":"kWh","type":"manual","sdm630_usb":"","sdm630_id":"","sdm630_counter":"l1"},"wasser":{"displayname":"Wasser","unit":"m\u00b3","type":"manual","sdm630_usb":"","sdm630_id":"","sdm630_counter":"l1"},"strom":{"displayname":"Strom","unit":"kWh","type":"manual","sdm630_usb":"","sdm630_id":"","sdm630_counter":"l1"},"heizung":{"displayname":"Heizung","unit":"kWh","type":"manual","sdm630_usb":"","sdm630_id":"","sdm630_counter":"l1"},"garten":{"displayname":"Garten","unit":"kWh","type":"manual","sdm630_usb":"","sdm630_id":"","sdm630_counter":"l1"},"lueftung_heizraum":{"displayname":"L\u00fcftung Heizraum","unit":"kWh","type":"manual","sdm630_usb":"","sdm630_id":"","sdm630_counter":"l1"},"display_flur":{"displayname":"Display Flur","unit":"kWh","type":"manual","sdm630_usb":"","sdm630_id":"","sdm630_counter":"l1"},"pv_haus":{"displayname":"PV Haus","unit":"kWh","type":"manual","sdm630_usb":"","sdm630_id":"","sdm630_counter":"all"},"heizung_modbus":{"displayname":"Heizung Modbus","unit":"kWh","type":"sdm630","sdm630_usb":"\/dev\/ttyUSB0","sdm630_id":"1","sdm630_counter":"all"}}}
8 changes: 4 additions & 4 deletions energiesparkonto.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#usage: python3 energiesparkonto.py host port database file.csv zaehler
#usage: python3 energiesparkonto.py host port database username password file.csv zaehler
import sys
import time
import os
from influxdb import InfluxDBClient
from datetime import datetime
import pytz

client = InfluxDBClient(host=str(sys.argv[1]), port=int(sys.argv[2]))
client = InfluxDBClient(host=str(sys.argv[1]), port=int(sys.argv[2]), username=str(sys.argv[4]), password=str(sys.argv[5]))
client.switch_database(str(sys.argv[3]))

file = open(str(sys.argv[4]))
file = open(str(sys.argv[6]))
for i in file:
if i[0] != "Z":
day = i[0:2]
Expand All @@ -30,7 +30,7 @@
timestamp = utc_dt.strftime("%Y-%m-%dT%H:%M:%S") + "Z"
json_body = [
{
"measurement": str(sys.argv[5]),
"measurement": str(sys.argv[7]),
"fields": {
"value": float(value),
"add": "energiesparkonto"
Expand Down
1 change: 1 addition & 0 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<title><?=$site_name?> - Energiezähler</title>
<link rel="stylesheet" href="style.css">
<link rel="icon" href="favicon.ico" />
<script src="jquery.js"></script>

</head>
<body>
Expand Down
8 changes: 4 additions & 4 deletions input.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from datetime import datetime
import pytz

client = InfluxDBClient(host=str(sys.argv[1]), port=int(sys.argv[2]))
client = InfluxDBClient(host=str(sys.argv[1]), port=int(sys.argv[2]), username=str(sys.argv[4]), password=str(sys.argv[5]))
client.switch_database(str(sys.argv[3]))

#command = "touch \"" + str(sys.argv) + "\""
#os.system(command)
timestamp = str(sys.argv[5]) + ":00"
timestamp = str(sys.argv[7]) + ":00"
#Zeit in UTC kovertieren:
local = pytz.timezone("Europe/Berlin")
naive = datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%S")
Expand All @@ -21,9 +21,9 @@

json_body = [
{
"measurement": str(sys.argv[4]),
"measurement": str(sys.argv[6]),
"fields": {
"value": float(sys.argv[6]),
"value": float(sys.argv[8]),
"add": "manual"
},
"time" : timestamp
Expand Down
13 changes: 9 additions & 4 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,26 @@ fi
#Installation starten
echo -e "${GREEN}Installiere Abhängigkeiten...${NC}"
apt-get install git sudo python3-pip
pip3 install minimalmodbus
pip3 install influxdb
echo -e "${GREEN}Installiere Webserver...${NC}"
apt-get install apache2 php -y
echo -e "${GREEN}Lade Energiezähler herunter...${NC}"
git clone https://github.com/jjk4/energiezaehler.git /var/www/html$installationpath
echo -e "${GREEN}Richte Energiezähler ein...${NC}"
chown -R www-data:www-data /var/www/html$installationpath
chmod 775 -R /var/www/html$installationpath
touch /etc/cron.d/energiezaehler
chown root:root /etc/cron.d/energiezaehler
chmod 755 /etc/cron.d/energiezaehler
usermod -a -G dialout www-data
if [ $databasetype != 'entfernt' ]
then
echo -e "${GREEN}Installiere Datenbank...${NC}"
apt-get install influxdb
apt-get install influxdb influxdb-client
influx -execute "CREATE DATABASE $database"
fi
echo -e "${GREEN}Richte Datenbank ein...${NC}"
cd /var/www/html$installationpath/
sudo -u www-data php installation.php $host $port $database
echo -e "${GREEN}Bitte füge die nachfolgende Zeile noch in die Datei /etc/crontab ein${NC}"
echo -e "${GREEN}00 12 * * * pi php /var/www/html$installationpath/add_values.php${NC}"
sudo -u www-data php installation.php $host $port $database "/var/www/html$installationpath"
echo -e "${GREEN}Das wars. Dein Energiezähler ist jetzt betriebsbereit. Schau dir doch vor der Nutzung noch das Wiki unter https://github.com/jjk4/energiezaehler/wiki an. Bei Problemen kannst du gerne einen Issue unter https://github.com/jjk4/energiezaehler/issues erstellen. Viel Spaß!${NC}"
1 change: 1 addition & 0 deletions installation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
$new_configuration['host'] = $argv[1];
$new_configuration['port'] = $argv[2];
$new_configuration['database'] = $argv[3];
$new_configuration['installationpath'] = $argv[4];
$new_configuration['zaehler'] = $config['zaehler'];
file_put_contents("config.json",json_encode($new_configuration));
?>
2 changes: 2 additions & 0 deletions jquery.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions query.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#command = "touch \"" + str(sys.argv) + "\""
#os.system(command)

client = InfluxDBClient(host=str(sys.argv[1]), port=int(sys.argv[2]))
client = InfluxDBClient(host=str(sys.argv[1]), port=int(sys.argv[2]), username=str(sys.argv[4]), password=str(sys.argv[5]))
client.switch_database(str(sys.argv[3]))

timestamp1 = str(sys.argv[5])
timestamp2 = str(sys.argv[6])
zaehler = str(sys.argv[4])
timestamp1 = str(sys.argv[7])
timestamp2 = str(sys.argv[8])
zaehler = str(sys.argv[6])

results = client.query("SELECT * FROM " + zaehler + " WHERE time > '" + timestamp1 + "' and time < '" + timestamp2 + "' tz('Europe/Berlin')")
points = results.get_points
Expand Down
Loading

0 comments on commit 4083b67

Please sign in to comment.