-
Notifications
You must be signed in to change notification settings - Fork 5
/
ToPvOutput.php
46 lines (38 loc) · 1.41 KB
/
ToPvOutput.php
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
<?php
namespace GoodWe;
class ToPvOutput
{
const PVOUTPUT_URL = 'https://pvoutput.org/service/r2/addstatus.jsp';
public static function send(array $inverter, GoodWeOutput $goodWeOutput)
{
if (!array_key_exists('pvoutput', $inverter)) {
throw new \Exception('No pvoutput details given');
}
$ch = curl_init();
$headers = [
'X-Pvoutput-Apikey: ' . $inverter['pvoutput']['apiKey'],
'X-Pvoutput-SystemId: ' . $inverter['pvoutput']['systemId'],
];
curl_setopt($ch, CURLOPT_URL,self::PVOUTPUT_URL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt(
$ch,
CURLOPT_POSTFIELDS,
http_build_query(
[
'd' => $goodWeOutput->getDateTime()->format('Ymd'),
't' => $goodWeOutput->getDateTime()->format('H:i'),
'v1' => $goodWeOutput->getGenerationToday() * 1000,
'v2' => $goodWeOutput->getPower() * 1000,
'v5' => $goodWeOutput->getTemperature(),
'v6' => $goodWeOutput->getVoltageAc1(),
]
)
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$serverOutput = curl_exec($ch);
curl_close ($ch);
echo 'PVOutput result: ' . $serverOutput . PHP_EOL;
}
}