-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampleSymconParser.php
More file actions
83 lines (56 loc) · 2.34 KB
/
ExampleSymconParser.php
File metadata and controls
83 lines (56 loc) · 2.34 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
<?php
//API Url
$url = 'https://vrmapi.victronenergy.com/v2/auth/login';
//Initiate cURL.
$ch = curl_init($url);
//The JSON data.
$jsonData = array(
'username' => '<UNSERNAME>',
'password' => '<PASSWORD>'
);
//Encode the array into JSON.
$jsonDataEncoded = json_encode($jsonData);
//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, false);
//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
//Execute the request
$response = json_decode(curl_exec($ch), true);
//print_r($response);
$token = $response['token'];
$idUser = $response['idUser'];
//$url1 = 'https://vrmapi.victronenergy.com/v2/installations/<INSTALLATION_ID>/system-overview';
$url1 = 'https://vrmapi.victronenergy.com/v2/users/'.$idUser.'/installations?extended=1';
//Initiate cURL.
$ch1 = curl_init($url1);
//Set the content type to application/json
//echo $url1;
//echo $token;
$authorization = "X-Authorization: Bearer " . $token;
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch1, CURLOPT_VERBOSE, false);
curl_setopt($ch1, CURLOPT_HTTPHEADER, array('Content-Type: application/json', $authorization));
//Execute the request
$resultVRM = json_decode(curl_exec($ch1), true);
//print_r($resultVRM);
SetValueFloat( 21366,$resultVRM['records']['0']['extended']['4']['rawValue']);
SetValueFloat( 21442,$resultVRM['records']['0']['extended']['3']['rawValue']);
SetValueString( 10326,$resultVRM['records']['0']['extended']['6']['formattedValue']);
$url1 = 'https://vrmapi.victronenergy.com/v2/installations/<INSTALLATION_ID>/overallstats';
//Initiate cURL.
$ch1 = curl_init($url1);
//Set the content type to application/json
//echo $url1;
//echo $token;
$authorization = "X-Authorization: Bearer " . $token;
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch1, CURLOPT_VERBOSE, false);
curl_setopt($ch1, CURLOPT_HTTPHEADER, array('Content-Type: application/json', $authorization));
//Execute the request
$resultVRM = json_decode(curl_exec($ch1), true);
//print_r($resultVRM);
SetValueFloat( 17964,$resultVRM['records']['today']['totals']['total_solar_yield']);