-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSAJ2.plugin.txt
164 lines (148 loc) · 6.67 KB
/
SAJ2.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
///////// <version>1.0.2</version>
///////// SAJ2 /////////////
///////// Plugin to extract CSAJ from web data for Toon ///////////////
///////// By Oepi-Loepi ///////////////
function getSolarData(passWord,userName,apiKey,siteid,urlString,totalValue){
if (debugOutput) console.log("*********SolarPanel Start getSolarData")
console.log("Start getStep1")
var xhr = new XMLHttpRequest()
var url = "https://fop.saj-electric.com/saj/login?lang=nl&username=" + userName + "&password=" + passWord + "&rememberMe=true"
xhr.open("POST", url, true);
xhr.setRequestHeader('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,application/signed-exchange;v=b3;q=0.9');
xhr.setRequestHeader('Accept-Encoding', 'gzip, deflate, br');
xhr.setRequestHeader( 'Accept-Language', 'nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7');
xhr.setRequestHeader( 'Cache-Control', 'max-age=0');
xhr.setRequestHeader( 'Connection', 'keep-alive');
xhr.setRequestHeader( 'Content-Length', '79');
xhr.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded');
xhr.setRequestHeader('DNT', '1');
xhr.setRequestHeader( 'Host', 'fop.saj-electric.com');
xhr.setRequestHeader( 'Origin', 'https://fop.saj-electric.com');
xhr.setRequestHeader( 'Referer', 'https://fop.saj-electric.com/saj/login');
xhr.setRequestHeader('sec-ch-ua', '" Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"');
xhr.setRequestHeader( 'sec-ch-ua-mobile', '?0');
xhr.setRequestHeader('Sec-Fetch-Dest', 'document');
xhr.setRequestHeader('Sec-Fetch-Mode', 'navigate');
xhr.setRequestHeader( 'Sec-Fetch-Site', 'same-origin');
xhr.setRequestHeader( 'Sec-Fetch-User', '?1');
xhr.setRequestHeader('Upgrade-Insecure-Requests', '1');
xhr.setRequestHeader('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36');
xhr.onreadystatechange = function() { // Call a function when the state changes.
if (xhr.readyState == XMLHttpRequest.DONE) {
if (xhr.status === 200 || xhr.status === 300 || xhr.status === 302) {
try {
if (debugOutput) console.log("xhr.status: " + xhr.status)
if (debugOutput) console.log(xhr.responseText)
getStep2();
}
catch (e){
currentPower = 0
parseReturnData(0,totalValue,todayValue,0,0,0,0, xhr.status,"error")
}
} else {
parseReturnData(currentPower,totalValue,0,0,0,0,0, xhr.status,"error")
}
}
}
xhr.send();
}
function getStep2(){
if (debugOutput) console.log("*********SolarPanel Start getStep2")
var xhr = new XMLHttpRequest()
var url = "https://fop.saj-electric.com/saj/monitor/site/getUserPlantList";
xhr.open("POST", url, true);
xhr.setRequestHeader('Connection', 'keep-alive');
xhr.onreadystatechange = function() { // Call a function when the state changes.
if (xhr.readyState == XMLHttpRequest.DONE) {
if (xhr.status === 200 || xhr.status === 300 || xhr.status === 302) {
try {
if (debugOutput) console.log(xhr.responseText)
var JsonString = xhr.responseText
var JsonObject= JSON.parse(JsonString)
var plantName = JsonObject.plantList[0].plantname
var plantUUID = JsonObject.plantList[0].plantuid
var curPower = JsonObject. plantList[0].nowPower
getStep3(plantUUID, curPower)
}
catch (e){
currentPower = 0
parseReturnData(0,totalValue,todayValue,0,0,0,0, xhr.status,"error")
}
} else {
parseReturnData(currentPower,totalValue,0,0,0,0,0, xhr.status,"error")
}
}
}
xhr.send();
}
function getStep3(plantUID, curPower){
if (debugOutput) console.log("*********SolarPanel Start getStep3")
var reqDate = new Date()
var d = reqDate.getDate()
var m = reqDate.getMonth()+1
var y = reqDate.getFullYear()
if (debugOutput) console.log("*********SolarPanel getStep3 date: " + y + "-" + m + "-" + d)
var url ="https://fop.saj-electric.com/saj/monitor/site/getPlantDetailInfo?plantuid=" + plantUID + "&clientDate=" + y + "-" + m + "-" + d
if (debugOutput) console.log("*********SolarPanel getStep3 url: " + url)
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.setRequestHeader('Connection', 'keep-alive');
xhr.onreadystatechange = function() { // Call a function when the state changes.
if (xhr.readyState == XMLHttpRequest.DONE) {
if (xhr.status === 200 || xhr.status === 300 || xhr.status === 302) {
try {
if (debugOutput) console.log(xhr.responseText)
var JsonString = xhr.responseText
var JsonObject= JSON.parse(JsonString)
currentPower = String(curPower*100/100)
totalValue = Math.floor(JsonObject.plantDetail.totalElectricity * 1000)
if (debugOutput) console.log("*********SolarPanel getStep3 currentPower: " + currentPower)
if (debugOutput) console.log("*********SolarPanel getStep3 totalValue: " + totalValue)
var plantSN = JsonObject.plantDetail.snList
getStep4(plantUID,plantSN,currentPower,totalValue)
}
catch (e){
currentPower = 0
parseReturnData(0,totalValue,todayValue,0,0,0,0, xhr.status,"error")
}
} else {
parseReturnData(currentPower,totalValue,0,0,0,0,0, xhr.status,"error")
}
}
}
xhr.send();
}
function getStep4(plantUID, plantSN, nowpower, totValue){
if (debugOutput) console.log("*********SolarPanel Start getStep4")
var reqDate = new Date()
var d = reqDate.getDate()
var m = reqDate.getMonth()+1
var y = reqDate.getFullYear()
if (debugOutput) console.log("*********SolarPanel getStep4 date: " + y + "-" + m + "-" + d)
var url = "https://fop.saj-electric.com/saj/monitor/site/getPlantDetailChart2?plantuid=" + plantUID + "&chartDateType=1&deviceSnArr=R5X2502J2208E10935&chartCountType=2&chartDay=" + + y + "-" + m + "-" + d
if (debugOutput) console.log("*********SolarPanel getStep4 url: " + url)
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.setRequestHeader('Connection', 'keep-alive');
xhr.onreadystatechange = function() { // Call a function when the state changes.
if (xhr.readyState == XMLHttpRequest.DONE) {
if (xhr.status === 200 || xhr.status === 300 || xhr.status === 302) {
try {
if (debugOutput) console.log(xhr.responseText)
var JsonString = xhr.responseText
var JsonObject= JSON.parse(JsonString)
var today2 = Math.floor(JsonObject.dayEnergy * 1000)
if (debugOutput) console.log("*********SolarPanel getStep3 today2: " + today2)
parseReturnData(nowpower,totValue,today2,0,0,0,0,xhr.status,"succes")
}
catch (e){
currentPower = 0
parseReturnData(0,totValue,todayValue,0,0,0,0, xhr.status,"error")
}
} else {
parseReturnData(nowpower,totValue,0,0,0,0,0, xhr.status,"error")
}
}
}
xhr.send();
}