forked from patience4711/ESP32-read-APS-inverters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AAA_HOMEPAGE.ino
236 lines (211 loc) · 8.14 KB
/
AAA_HOMEPAGE.ino
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
const char ECU_HOMEPAGE[] PROGMEM = R"=====(
<!DOCTYPE html><html><head>
<meta http-equiv="refresh" content="112">
<meta charset='utf-8' name="viewport" content="width=device-width, initial-scale=1">
<title>ESP32-ECU</title>
<link rel="stylesheet" type="text/css" href="/STYLESHEET">
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<style>
body {
background-color: #EEE;
}
.btn {
background-color: #199319;
color: white;
padding: 5px 22px;
border-radius:6px;
}
.btn:hover {background: #eeeF; color:black;}
span {
padding: 6px;
}
table, th, td {
border: 2px solid blue; font-size:16px; padding:6px; text-align:center; border-collapse:collapse;backgound-color:#dfff80;
}
tr {background-color:#ccffcc;}
td { width:70px; }
@media only screen and (max-width: 800px) {
th, td { width:60px; font-size:11px; }
tr {height:35px;}
.btn { padding: 5px 18px; font-size:10px;}
}
</style>
<script type="text/javascript" src="JAVASCRIPT"></script>
<script type="text/javascript" src="SECURITY"></script>
</head>
<body onload='loadScript()'>
<div id='msect'>
<ul>
<li><a href='/ABOUT'>info</a></li>
<li><a href='/LOGPAGE'>log</a></li>
<li id="ml" style='float:right; display:none'><a id='haha' href='/MENU'>menu</a></li>
</ul>
</div>
<div id='msect'>
<kop>HANSIART ESP32 ECU</kop>
</div>
<div id='msect'>
<div class='divstijl' id='maindiv'>
<center>
<p>polling from <span id='srt'></span> to <span id='sst'></span></p>
<h4>POWER (W) AND TODAY'S ENERGY (kWh)</h4>
<div id='noOutput' style='display:block'>
<h4 style='color:red'>waiting for output</h4>
</div>
<div id="4channel" style='display:none;'>
<center><table>
<tr style='Background-color:lightblue; font-weight:bold; text-align:center; border:4px solid black;'>
<td>inv.<td>panel 0<td>panel 1<td>panel 2<td>panel 3<td>kWh</td></tr>
<tr id="r0" style="display:none;"><td id="i0"></td><td id="p00"></td><td id="p01"></td><td id="p02"></td><td id="p03"></td><td id="e0"></td></tr>
<tr id="r1" style="display:none;"><td id="i1"></td><td id="p10"></td><td id="p11"></td><td id="p12"></td><td id="p13"></td><td id="e1"></td></tr>
<tr id="r2" style="display:none;"><td id="i2"></td><td id="p20"></td><td id="p21"></td><td id="p22"></td><td id="p23"></td><td id="e2"></td></tr>
<tr id="r3" style="display:none;"><td id="i3"></td><td id="p30"></td><td id="p31"></td><td id="p32"></td><td id="p33"></td><td id="e3"></td></tr>
<tr id="r4" style="display:none;"><td id="i4"></td><td id="p40"></td><td id="p41"></td><td id="p42"></td><td id="p43"></td><td id="e4"></td></tr>
<tr id="r5" style="display:none;"><td id="i5"></td><td id="p50"></td><td id="p51"></td><td id="p52"></td><td id="p53"></td><td id="e5"></td></tr>
<tr id="r6" style="display:none;"><td id="i6"></td><td id="p60"></td><td id="p61"></td><td id="p62"></td><td id="p63"></td><td id="e6"></td></tr>
<tr id="r7" style="display:none;"><td id="i7"></td><td id="p70"></td><td id="p71"></td><td id="p72"></td><td id="p73"></td><td id="e7"></td></tr>
<tr id="r8" style="display:none;"><td id="i8"></td><td id="p80"></td><td id="p81"></td><td id="p82"></td><td id="p83"></td><td id="e8"></td></tr>
<tr id="r9" style="display:none;"><td colspan="5" style="text-align:right;">total of all inverters </td><td id="e9"></td></tr>
</table>
</div>
<div id="busy">
<span style="color:red;"><h3>checking / initialyzing zigbee network...</h3></span><br>
</div>
<div id="failed" style="display:none;">
<span style='color:red;'><h3>the cc25xx is not working, check the log.</h3></span><br>
</div>
</center>
</div>
</div></body>
</html>
)=====";
const char JAVA_SCRIPT[] PROGMEM = R"=====(
var term;
var table_row;
var cnt = 9;
var totalEn = 0;
window.addEventListener("beforeunload", function(event) {
console.log("UNLOAD:1");
getTimes();
});
function loadScript() {
getTimes();
getAll();
}
function celbgc(cel) {
//background color of the cells
if(cel.startsWith("e")) {
document.getElementById(cel).style = "background-color:#c6ff1a"; }
else if(cel.startsWith("i")) {
document.getElementById(cel).style = "background-color:#00cc44";}
else {document.getElementById(cel).style = "background-color:#a6a6a6";
}
}
setInterval(function loadData() {
getAll();
},15000);
function getAll() {
totalEn = 0;
for (let i = 0; i < cnt; i++) {
term = "get.Power?inv=" + i;
table_row = "inv" + i;
//console.log("table_row = " + table_row);
//console.log("term = " + term);
getData(i);
}
}
function getData(invnr) {
//console.log("term = " + term);
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var antwoord = this.responseText;
//console.log("answer = " + antwoord);
var obj = JSON.parse(antwoord);
var nm = obj.nm;
var polled = obj.polled;
var Type = obj.type;
const pw = [4];
pw[0] = obj.p0;
pw[1] = obj.p1;
pw[2] = obj.p2;
pw[3] = obj.p3;
var st = obj.state;
var sl = obj.sleep;
var eN = obj.eN;
cnt = parseInt(obj.count);
var rem = obj.remote;
if(rem == 0) {document.getElementById("ml").style.display = "block";}
if(st == "11") {
document.getElementById("busy").style.display = "block";
} else {
document.getElementById("busy").style.display = "none";
document.getElementById("failed").style.display = "none";
}
if(st == "0" || st == "25") {
document.getElementById("failed").style.display = "block";
}
var main = document.getElementById("maindiv")
var slp = document.getElementById("sleep")
if(sl == "1") {
main.style.background="grey";
document.getElementById("noOutput").style.display = "none";
} else {
main.style.background="linear-gradient(#e8edc8, #c8eaed)";
}
if(nm == "N/A") {return 0;}
var regel = "r" + String(invnr);
document.getElementById(regel).style.display="table-row";
var cel = "i" + String(invnr);
document.getElementById(cel).innerHTML = "<a href='/details?inv=" + String(invnr) + "'><button class='btn'>" + String(invnr) + "</button></a>";
celbgc(cel);
for (let z=0; z < 4 ; z++) {
cel = "p" + String(invnr) + z; //e,g, p00
if (pw[z] == "n/e") {
celbgc(cel);
}
else
{
document.getElementById(cel).innerHTML = pw[z];
}
}
var cel = "e" + String(invnr);
celbgc(cel);
if (eN != "n/e") {
//if(polled == "1") {
document.getElementById(cel).innerHTML = eN;
if(cnt > 1){
totalEn = totalEn + parseFloat(eN);
celbgc("e9");
document.getElementById("r9").style.display="table-row";
document.getElementById("e9").innerHTML = totalEn.toFixed(2);
}
// } else {
// document.getElementById(cel).innerHTML = "n/a";
// }
} else {
document.getElementById(cel).innerHTML = "n/e";
}
document.getElementById("noOutput").style.display = "none";
document.getElementById("4channel").style.display = "block";
}
}
xhttp.open("GET", term, true);
xhttp.send();
}
function getTimes() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var antwoord = this.responseText;
var obj = JSON.parse(antwoord);
var srt = obj.srt;
var sst = obj.sst;
document.getElementById("srt").innerHTML = srt;
document.getElementById("sst").innerHTML = sst;
}
}
xhttp.open("GET", "get.Times", true);
xhttp.send();
}
)=====";