-
Notifications
You must be signed in to change notification settings - Fork 5
/
SOLIS1.plugin.txt
96 lines (92 loc) · 3.8 KB
/
SOLIS1.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
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
///////// <version>1.0.1</version>
///////// SOLIS1 /////////////
///////// Plugin to extract Ginglong Solis Solar data for Toon ///////////////
///////// By Oepi-Loepi ///////////////
function getSolarData(passWord,userName,apiKey,siteid,urlString,totalValue){
if (debugOutput) console.log("*********SolarPanel Start getSolarDataStep1")
var http = new XMLHttpRequest()
var url = "http://apic-cdn.solarman.cn/v/ap.2.0/cust/user/login?user_id=" + userName+ "&user_pass=" + passWord
http.open("GET", url, true);
http.onreadystatechange = function() { // Call a function when the state changes.
if (http.readyState === 4) {
if (http.status === 200) {
try {
var JsonString = http.responseText
var JsonObject= JSON.parse(JsonString)
if (parseInt(JsonObject.result) === 5){if (debugOutput) cconsole.log("*********SolarPanel Wrong password")}
if (parseInt(JsonObject.result) === 11){if (debugOutput) console.log("*********SolarPanel Wrong username")}
var token = JsonObject.token
var uid = JsonObject.uid
getStep2(uid,token)
}
catch (e){
currentPower = 0
parseReturnData(0,totalValue,todayValue,0,0,0,0, http.status,"error")
}
} else {
parseReturnData(0,totalValue,0,0,0,0,0, http.status,"error")
}
}
}
http.send()
}
function getStep2(uid,token){
if (debugOutput) console.log("*********SolarPanel Start getSolarDataStep2")
var http = new XMLHttpRequest()
var url = "http://apic-cdn.solarman.cn/v/ap.2.0/plant/find_plant_list?uid=" + uid + "&sel_scope=1&sort_type=1"
http.open("GET", url, true);
http.setRequestHeader('token', token);
http.onreadystatechange = function() { // Call a function when the state changes.
if (http.readyState === 4) {
if (http.status === 200) {
try {
var today2
var JsonString = http.responseText
var JsonObject= JSON.parse(JsonString)
var plant_id = JsonObject.list[0].plant_id
getStep3(uid,token,plant_id)
}
catch (e){
currentPower = 0
parseReturnData(0,totalValue,todayValue,0,0,0,0, http.status,"error")
}
} else {
parseReturnData(0,totalValue,0,0,0,0,0, http.status,"error")
}
}
}
http.send();
}
function getStep3(uid,token,plant_id){
if (debugOutput) console.log("*********SolarPanel Start getSolarDataStep3")
var http = new XMLHttpRequest()
var url = "http://apic-cdn.solarman.cn/v/ap.2.0/plant/get_plant_overview?uid=" + uid + "&plant_id=" + plant_id
if (debugOutput) console.log("*********SolarPanel url : " + url)
http.open("GET", url, true);
http.setRequestHeader('token', token);
http.onreadystatechange = function() { // Call a function when the state changes.
if (http.readyState === 4) {
if (http.status === 200) {
try {
var today2
var JsonString = http.responseText
var JsonObject= JSON.parse(JsonString)
currentPower = parseInt(JsonObject.power_out.power)
today2 = parseInt(JsonObject.power_out.energy_day * 1000)
totalValue = parseInt(JsonObject.power_out.energy_accu * 1000)
if (isNaN(currentPower))currentPower=0
if (isNaN(today2))today2=0
if (isNaN(totalValue))totalValue=0
parseReturnData(currentPower,totalValue,today2,0,0,0,0,http.status,"succes")
}
catch (e){
currentPower = 0
parseReturnData(0,totalValue,todayValue,0,0,0,0, http.status,"error")
}
} else {
parseReturnData(0,totalValue,0,0,0,0,0, http.status,"error")
}
}
}
http.send();
}