Skip to content
Permalink
Browse files

Version 0.0.9

 - Fixed silly warning about 'Data loss: 0 bytes'.
 - Added support for more three-phase inverter firmware versions.
 - Fixed issue with pvo-upload.php in western hemisphere timezones.
 - Added PVOutput upload script for three-phase inverters.
  • Loading branch information
Jerrythafast committed Jan 23, 2019
1 parent e4c2576 commit 4a559375d948579155e126ef8f68b74c9c87e11c
Showing with 84 additions and 4 deletions.
  1. +7 −1 README.txt
  2. +5 −2 opt/se-logger/liveupdate.py
  3. +70 −0 opt/se-logger/pvo-upload-3phase.php
  4. +2 −1 opt/se-logger/pvo-upload.php
@@ -1,4 +1,4 @@
VERSION 0.0.8
VERSION 0.0.9

===============================================================================
INSTALLATION INSTRUCTIONS
@@ -86,6 +86,12 @@ commands used. Tested with Ubuntu 16.04, Python 2.7.11, MySQL 5.7.12, PHP 7.0.
===============================================================================
CHANGELOG

v0.0.9
- Fixed silly warning about 'Data loss: 0 bytes'.
- Added support for more three-phase inverter firmware versions.
- Fixed issue with pvo-upload.php in western hemisphere timezones.
- Added PVOutput upload script for three-phase inverters.

v0.0.8
- Auto-reconnect to the database if a timeout occurs, and retry connecting up
to 5 times.
@@ -2,6 +2,8 @@
import struct, sys, MySQLdb, time
from collections import namedtuple

__version__ = "0.0.9"

# SETTINGS
inverter_private_key = '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
db_user = "dbuser"
@@ -234,7 +236,8 @@ def give_up_gaps(self, pcaptime):
if len(self.tcp_streams[sid][2]) and pcaptime - min(self.tcp_streams[sid][2][x][2] for x in self.tcp_streams[sid][2]) >= 60:
# Could not close gap to out-of-order data within a minute, probably missed something!
newnext = min(self.tcp_streams[sid][2])
eprint("%08x DATA LOSS %i bytes!" % (sid, newnext-self.tcp_streams[sid][0]))
if newnext > self.tcp_streams[sid][0]:
eprint("%08x DATA LOSS %i bytes!" % (sid, newnext-self.tcp_streams[sid][0]))
self.tcp_streams[sid][0] = newnext

def get_out_of_order_bytes(self, pcaptime):
@@ -429,7 +432,7 @@ def parse0500(data):
'p_apparent': inv.Papparent,
'p_reactive': inv.Preactive
}
elif type == 0x0011 and length in (264,): # 3ph inverter
elif type == 0x0011 and length in (200, 264): # 3ph inverter
inv = SEDataInverter3.parse(data, pos + 12)
yield {
'inv_id': id & ~0x00800000,
@@ -0,0 +1,70 @@
<?php
//Version 0.0.9
//SETTINGS
define("DB_HOST", "localhost");
define("DB_NAME", "solaredge");
define("DB_USERNAME", "dbuser");
define("DB_PASSWORD", "dbpassword");
define("PVO_API_KEY", "a2726abcfd6254409e725b628cfaed293745dbca");
define("PVO_SYSTEM_ID", "12345");



$db = new PDO(
"mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=utf8", DB_USERNAME, DB_PASSWORD,
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC]);

$q = $db->query(
'SELECT timestamp, p_active, temperature, v_dc, se_day ' .
'FROM (' .
'SELECT ' .
'timestamp, p_active1+p_active2+p_active3 p_active, temperature, v_dc, ' .
'@curdate := FROM_UNIXTIME(timestamp, "%Y%m%d") date, ' .
'@prevsum := IF(@prevdate = @curdate, @prevsum + de_day, de_day) se_day, ' .
'@prevdate := @curdate date2 ' .
'FROM telemetry_inverter_3phase ' .
'JOIN (SELECT @prevsum := 0, @curdate := NULL, @prevdate := NULL) vars ' .
'WHERE timestamp >= (SELECT IFNULL(UNIX_TIMESTAMP(FROM_UNIXTIME(pvo_last_live, "%Y%m%d")), 0) FROM live_update) ' .
'ORDER BY timestamp' .
') x ' .
'WHERE timestamp > (SELECT pvo_last_live FROM live_update) ' .
'LIMIT 100');
if($q === false)
die("Could not get data!\n");

$lastdate = 0;
$data = array();
while($row = $q->fetch()){
array_push($data, implode(",", [
date("Ymd", $row["timestamp"]),
date("H:i", $row["timestamp"]),
round($row["se_day"]),
round($row["p_active"]),
"",
"",
$row["temperature"] == 0? "" : $row["temperature"],
$row["v_dc"] == 0? "" : $row["v_dc"]
]));
$lastdate = $row["timestamp"];
}
$data = implode(";", $data);
if(!$data)
exit;

$c = curl_init("http://pvoutput.org/service/r2/addbatchstatus.jsp");
curl_setopt_array($c, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FAILONERROR => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => "data=" . $data,
CURLOPT_HTTPHEADER => [
"X-Pvoutput-Apikey: " . PVO_API_KEY,
"X-Pvoutput-SystemId: " . PVO_SYSTEM_ID
]
]);
if(curl_exec($c) === false)
die("cURL error, exiting: " . curl_error($c) . "\n");

$db->prepare("UPDATE live_update SET pvo_last_live = ?")->execute([$lastdate]);
?>
@@ -1,4 +1,5 @@
<?php
//Version 0.0.9
//SETTINGS
define("DB_HOST", "localhost");
define("DB_NAME", "solaredge");
@@ -24,7 +25,7 @@
'@prevdate := @curdate date2 ' .
'FROM telemetry_inverter ' .
'JOIN (SELECT @prevsum := 0, @curdate := NULL, @prevdate := NULL) vars ' .
'WHERE timestamp >= (SELECT UNIX_TIMESTAMP(FROM_UNIXTIME(pvo_last_live, "%Y%m%d")) FROM live_update) ' .
'WHERE timestamp >= (SELECT IFNULL(UNIX_TIMESTAMP(FROM_UNIXTIME(pvo_last_live, "%Y%m%d")), 0) FROM live_update) ' .
'ORDER BY timestamp' .
') x ' .
'WHERE timestamp > (SELECT pvo_last_live FROM live_update) ' .

0 comments on commit 4a55937

Please sign in to comment.
You can’t perform that action at this time.