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
| <?php
$filename = './dumprequest'.time().'.txt';
$file = file_get_contents('php://input');
//strip useless data
$file = substr($file, 20);
if ($file != "") {
//echo date("d-m H:i:s", substr($filename,11, -4))." - ";
//strip useless data
$file = substr($file, 0, -5);
$file = bin2hex($file);
/*echo $file;
echo "-";
echo "Vpv1: ".(hexdec(substr($file, 0, 4))/10)."|";
echo "Vpv2: ".(hexdec(substr($file, 4, 4))/10)."| ";
echo "Ipv1: ".(hexdec(substr($file, 8, 4))/10)." | ";
echo "Ipv2: ".(hexdec(substr($file, 12, 4))/10)." | ";
echo "cur: ".hexdec(substr($file, 28, 4))." | "; #curr usage
echo "Etotal: ".(hexdec(substr($file, 40, 16))/10)." | "; #eTotal :)
//echo hexdec(substr($file, 56, 8))." | ";
echo "Etoday: ".(hexdec(substr($file, 88, 4))/10)." | "; #eToday
echo "Vac: ".(hexdec(substr($file, 16, 4))/10)." | ";
echo "Iac: ".(hexdec(substr($file, 20, 4))/10)." | ";
echo "Fac: ".(hexdec(substr($file, 24, 4))/100)." | ";
echo "Temp: ".(hexdec(substr($file, 36, 4))/10)." | ";
echo "Htotal: ".(hexdec(substr($file, 56, 8)))." | ";
echo "?: ".(hexdec(substr($file, 80, 4)))." | ";
echo "Generating: ".(hexdec(substr($file, 34, 2)))." | "; # Generating or waiting
echo "\n";*/
mysql_query("INSERT INTO `zonnepanelen` (`date`, `vpv1`, `vpv2`, `ipv1`, `ipv2`, `cur`, `etotal`, `etoday`, `vac`, `iac`, `fac`, `temp`, `htotal`, `generating`, `raw`)
VALUES
(NOW(),
'".(hexdec(substr($file, 0, 4))/10)."',
'".(hexdec(substr($file, 4, 4))/10)."',
'".(hexdec(substr($file, 8, 4))/10)."',
'".(hexdec(substr($file, 12, 4))/10)."',
'".hexdec(substr($file, 28, 4))."',
'".(hexdec(substr($file, 40, 16))/10)."',
'".(hexdec(substr($file, 88, 4))/10)."',
'".(hexdec(substr($file, 16, 4))/10)."',
'".(hexdec(substr($file, 20, 4))/10)."',
'".(hexdec(substr($file, 24, 4))/100)."',
'".(hexdec(substr($file, 36, 4))/10)."',
'".(hexdec(substr($file, 56, 8)))."',
'".(hexdec(substr($file, 34, 2)))."',
'Url: ".$_SERVER['REQUEST_URI']." - ".$file."');
");
if(date('i')%5==0){
$data = [];
$data["d"] = date("Ymd"); //yyyymmdd
$data["t"] = date("H:i"); //hh:mm
$data["v1"] = (hexdec(substr($file, 88, 4))*100); // watt hours
$data["v2"] = hexdec(substr($file, 28, 4)); // watt
$data["v6"] = ((hexdec(substr($file, 0, 4))/10)+(hexdec(substr($file, 4, 4))/10)); // voltage
$data["v5"] = (hexdec(substr($file, 36, 4))/10); // degrees
$headers = "Content-type: application/x-www-form-urlencoded\r\n";
$headers .= "X-Pvoutput-Apikey: PVOUTPUTAPIKEYHIER\r\n";
$headers .= "X-Pvoutput-SystemId: SYSTEMIDHIER\r\n";
$options = [
"http" => [
"header" => $headers,
"method" => "POST",
"content" => http_build_query($data)
]
];
$context = stream_context_create($options);
$output = file_get_contents("http://pvoutput.org/service/r2/addstatus.jsp", false, $context);
}
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://goodwe-power.com".$_SERVER['REQUEST_URI'] );
//curl_setopt($ch, CURLOPT_URL, "http://goodwe-power.com/Acceptor/DataCRC" );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents('php://input'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
$result=curl_exec ($ch);
curl_close($ch);
//$result = substr($result, 0, -6);
// Extra sec ?? (0xaa) eindkarakter?
//$result = $result.chr(0x00).chr(0x00).chr(0x01).chr(0xFF).chr(0xaa).chr(0x00);
if ($_SERVER['REQUEST_URI'] == "/Acceptor/GetSendInterval") {
file_put_contents($filename, file_get_contents('php://input')."\n\nreturn: ".$result);
}
print_r($result); |