-
Notifications
You must be signed in to change notification settings - Fork 5
/
PVOUTPUT1.plugin.txt
51 lines (48 loc) · 2.43 KB
/
PVOUTPUT1.plugin.txt
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
///////// <version>1.0.3</version>
///////// PVOUTPUT1 /////////////
///////// Plugin to extract PVoutput data for Toon ///////////////
///////// By Oepi-Loepi ///////////////
function getSolarData(passWord,userName,apiKey,siteid,urlString,totalValue){
if (debugOutput) console.log("*********SolarPanel Start getPVOutputData")
var http = new XMLHttpRequest()
var url = "https://pvoutput.org/service/r2/getstatus.jsp?stats=1"
http.open("POST", url, true)
http.setRequestHeader("X-Pvoutput-Apikey", apiKey)
http.setRequestHeader("X-Pvoutput-SystemId", siteid)
http.onreadystatechange = function() { // Call a function when the state changes.
if (http.readyState === 4) {
if (http.status === 200) {
var today2
var pvoutputararray = http.responseText.split(",")
currentPower = parseInt(pvoutputararray[1])
today2 = parseInt(pvoutputararray[0])
getPVOutputData2(apiKey,siteid,currentPower,today2)
} else {
parseReturnData(currentPower,totalValue,0,0,0,0,0, http.status,"error")
}
}
}
http.send();
}
function getPVOutputData2(apiKey,siteid,currentPower,today2){
if (debugOutput) console.log("*********SolarPanel Start getPVOutputData2")
var http = new XMLHttpRequest()
var url = "https://pvoutput.org/service/r2/getstatistic.jsp"
http.open("POST", url, true)
http.setRequestHeader("X-Pvoutput-Apikey", apiKey)
http.setRequestHeader("X-Pvoutput-SystemId", siteid)
http.onreadystatechange = function() { // Call a function when the state changes.
if (http.readyState === 4) {
if (http.status === 200) {
if (debugOutput) console.log("*********SolarPanel PVOutput4: " + http.responseText)
var pvoutputararray = http.responseText.split(",")
totalValue = parseInt(pvoutputararray[0])
parseReturnData(currentPower,totalValue,today2,0,0,0,0,http.status,"succes")
} else {
if (debugOutput) console.log("*********SolarPanel error: " + http.status)
parseReturnData(currentPower,totalValue,0,0,0,0,0, http.status,"error")
}
}
}
http.send();
}