forked from B-Mqn/Zeversolar.php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzever.php
More file actions
141 lines (102 loc) · 3.68 KB
/
zever.php
File metadata and controls
141 lines (102 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
//Zever.php Created by Bman - https://github.com/B-Mqn/Zeversolar.php
//head over to https://forum.pvoutput.org to discuss it.
// -------Manually run command-------
// /usr/bin/php /share/Web/zeversolar/zever.php
// -------Cron Script-------
// crontab -e
// */5 * * * * /usr/local/apache/bin/php /share/Web/zeversolar/zever.php
// -------View Log-------
// cat /share/Web/zeversolar/logs/2019-05-19_zever.log //view log
// tail -f /share/Web/zeversolar/logs/2019-05-19_zever.log //View log Realtime
// nano /share/Web/zeversolar/logs/2019-05-19_zever.log //Edit Log
//-------------------------------------------------------------------------------------------------
// -------Configuration Options-------
$dataManagerIP = "192.168.x.xx"; //Inverter IP Address
$pvOutputApiKEY = "pvoutput key"; //PvOutput Api Key
$pvOutputSID = "pvoutput systemid"; //PvOutput System ID
//add Timezone info
$country = "Europe";
$capitalCity ="Warsaw";
//--------------------------------------------------------------------------------------------------
// !!!!!!!!!!!!!!!! DONT EDIT BELOW HERE !!!!!!!!!!!!!!!!!!!
//--------------------------------------------------------------------------------------------------
// Define Date & Time
date_default_timezone_set("$country/$capitalCity");
$system_time= time();
$date = date('Ymd', time());
$time = date('H:i', time());
// Inverter & API URL
$pvOutputApiURL = "http://pvoutput.org/service/r2/addstatus.jsp?";
$inverterDataURL = "http://".$dataManagerIP."/home.cgi";
$context = stream_context_create(array('http'=>array('protocol_version'=>'1.1')));
// x Attepmts at connecting to inverter
$attempts = 0;
do {
$attempts++;
echo "Attempt $attempts\n";
$result = file_get_contents($inverterDataURL, false, $context);
if (!$result) {
echo "Attempt $attempts has failed. Waiting 10 seconds.\n";
sleep(10);
}
} while( !$result && $attempts < 5);
// Expanding data from api call
echo $result;
$lines=explode("\n",$result);
$inverterPowerLive = $lines[10];
$kwh = $lines[11];
//Echo kWh reading before
Echo "\n";
Echo "$kwh \n";
Echo "\n";
//Addzero if needed & echo result
$kwh_parts=explode('.', $kwh);
if (strlen($kwh_parts[1]) == 1) {
$kwh_parts[1] = '0' . $kwh_parts[1];
$kwh=join('.',$kwh_parts);
}
Echo "\n";
Echo "$kwh \n";
//Convert kWh into Wh & Echo Result
$inverterEnergyDayTotal = $kwh * 1000;
if ($kwh > 0) {
$inverterEnergyDayTotal = $kwh * 1000;
} else {
$inverterEnergyDayTotal =" ";
}
Echo "$inverterEnergyDayTotal \n";
Echo "\n";
// Push to PVOutput
$pvOutputURL = $pvOutputApiURL
. "key=" . $pvOutputApiKEY
. "&sid=" . $pvOutputSID
. "&d=" . $date
. "&t=" . $time
. "&v1=" . $inverterEnergyDayTotal
. "&v2=" . $inverterPowerLive;
file_get_contents(trim($pvOutputURL));
//Print Values to Console
Echo "\n";
Echo "d \t $date\n";
Echo "t \t $time\n";
Echo "v1 \t $inverterEnergyDayTotal\n";
Echo "v2 \t $inverterPowerLive\n";
Echo "\n";
Echo "Sending data to PVOutput.org \n";
Echo "$pvOutputURL \n";
Echo "\n";
// Push to log file
// log file Output ------ attempts to contact inverter, Date, Time, V1, V2 -------
// using the FILE_APPEND flag to append the content to the end of the file
$file=date('Y-m-d').'_zever.log';
$logData = $attempts
. "," . $date
. "," . $time
. "," . $inverterEnergyDayTotal
. "," . $inverterPowerLive;
//file_put_contents($file, ($logData . "\r\n"), FILE_APPEND);
file_put_contents("/share/Web/zeversolar/logs/$file", ($logData . "\r\n"), FILE_APPEND);
Echo "And output log to $file \n";
Echo "\n";
?>