-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard135.html
More file actions
296 lines (245 loc) · 10 KB
/
dashboard135.html
File metadata and controls
296 lines (245 loc) · 10 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
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<!DOCTYPE HTML>
<html>
<head>
<title>Dashboard 135</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
</head>
<body onload="loading()">
<script src="https://cdn.jsdelivr.net/npm/particle-api-js@8/dist/particle.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
<script>
//Get you accesstoken from LocalStorage if you've logged in before.
var token = localStorage.getItem("token");
var particle = new Particle();
var logged_in=false;
var txtImport="", txtProd="", txtDivert="", txtConso="";
function loading(){
if(token){ // on a déjà un token
document.getElementById('login-window').style.display="none"; // on cache la fenetre de login
document.getElementById("BoutonLogin").innerHTML = "Logout";
// ListDevices();
UpdateVariables();
//Get your devices events
particle.getEventStream({ deviceId: '28002d000847343232363230', auth: token }).then(function(stream) {
stream.on('event', function(data) {
//console.log("Event: ", data);
var re = /ct4:(-*\d*)/; //"ct4:362"
var str = data.data;
txtProd = str.match(re);
//console.log("ct4: ", txtProd[1]);
document.getElementById("TxtProdW").innerHTML = "Prod="+txtProd[1]+"W";
});
});
particle.getEventStream({ deviceId: 'e00fce68b92c3cf97750f326', auth: token }).then(function(stream) {
stream.on('event', function(data) {
//console.log("Event: ", data);
var re = /ct1:(-*\d*),/; //"ct1:56,vrms:23606,divert:0.000000"
var str = data.data;
txtImport = str.match(re);
//console.log("ct1: ", txtImport[1]);
if(parseInt(txtImport[1], 10) < 0){
document.getElementById("txtImportW").innerHTML = "Export="+Math.abs(txtImport[1])+"W";
document.getElementById("classTxtImport").className="p-3 mb-2 bg-success text-white";
}
else{
document.getElementById("txtImportW").innerHTML = "Import="+txtImport[1]+"W";
document.getElementById("classTxtImport").className="p-3 mb-2 bg-danger text-white";
}
txtConso = parseInt(txtImport[1], 10) + parseInt(txtProd[1], 10);
document.getElementById("txtConsoW").innerHTML = "Conso="+txtConso+"W";
//console.log("txtConso: ", txtConso);
var re2 = /divert:(-*\d*)/; //"ct1:56,vrms:23606,divert:0.000000"
txtDivert = str.match(re2);
//console.log("Divert: ", txtDivert[1]);
document.getElementById("TxtDivertW").innerHTML = "Divert="+txtDivert[1]+"W";
if(parseInt(txtDivert[1], 10) > 0)
document.getElementById("classTxtDivert").className="p-3 mb-2 bg-warning text-white";
else
document.getElementById("classTxtDivert").className="p-3 mb-2 bg-info text-white";
});
});
particle.getEventStream({ deviceId: 'e00fce68dd79f07fb2c34989', auth: token }).then(function(stream) {
stream.on('event', function(data) {
//console.log(data.data);
txtYaourtiere = data.data;
if(isNaN(txtYaourtiere)){
document.getElementById("TxtStatusYaourtiere").innerHTML = "Status="+txtYaourtiere;
}
else{
document.getElementById("TxtTempYaourtiere").innerHTML = "Temperature="+txtYaourtiere+"°C";
}
});
});
}
}
//Delete accesstoken from LocalStorage, and reload page.
function logout() {
localStorage.removeItem("token");
window.location.reload();
}
function login() {
if(!token){ //si pas encore de token
var login=document.getElementById('InputLogin').value;
var pass=document.getElementById('InputPassword').value;
particle.login({username: login, password: pass}).then(
function(data) {
token=data.body.access_token;
localStorage.setItem("token",token);
console.log(token);
// ListDevices();
// UpdateVariables();
loading();
},
function (err) {
console.log('Could not log in.', err);
}
);
}
else{
logout();
}
}
function ListDevices(){
particle.listDevices({ auth: token }).then(
function(data){
//console.log(data);
for(var ii = 0; ii < data.body.length; ii++) {
var dev = data.body[ii];
//console.log("dev ii=" + ii, dev);
// The entries that come back have the following things in dev:
// cellular: false
// connected: true
// id: "<yourdeviceid>"
// last_app: null
// last_heard: "2016-03-18T18:11:36.183Z"
// last_ip_address: "<youripaddress>"
// name: "test4"
// platform_id: 6
// product_id: 6
// status: "normal"
if (dev.connected) {
console.log(dev.name, dev.id, "is connected");
console.log(dev);
var newHTML="<div class=\"card text-white bg-info mb-3\"><div class=\"card-body\"> <h5 class=\"card-title\">"+dev.name+"</h5>";
// variables
if(Object.keys(dev.variables).length>0){
newHTML += "<div class=\"container\">";
for(i=0; i<Object.keys(dev.variables).length; i++){
newHTML += "<div class=\"row\"><div class=\"col-sm\">"+Object.keys(dev.variables)[i]+"</div>";
//newHTML += "<div class=\"col-sm\">VALEUR</div>";
newHTML += "</div>";
}
newHTML += "</div>"; // fin du container de la ligne
}
// fonctions
newHTML += "<div class=\"container\">";
for(i=0; i<dev.functions.length; i++){
newHTML += "<div class=\"row\"><div class=\"col-sm\"><button type=\"button\" class=\"btn btn-primary\">"+dev.functions[i]+"()</button></div>";
//newHTML += "<div class=\"col-sm\">VALEUR</div>";
newHTML += "</div>";
}
newHTML += "</div>"; // fin du container de la ligne
newHTML += "</div> </div>";
$("div.card-deck").append(newHTML);
}
}
},
function(err){
console.log('Could not get devices.', err);
}
);
}
function UpdateVariables(){
particle.getVariable({ deviceId: '270043000447343232363230', name: 'bCmdChauffage', auth: token }).then(
function(data) {
document.getElementById("TxtCmdChauffage").innerHTML = "CmdChauffage="+data.body.result;
},
function(err) {
console.log('An error occurred while getting attrs:', err);
document.getElementById("TxtCmdChauffage").innerHTML = "Erreur lecture CmdChauffage";
});
}
function Chauffage(CmdChauffage) {
console.log("CmdChauffage=",CmdChauffage);
var event_data;
if(CmdChauffage==1){
event_data="ON";
}
else event_data="OFF"
var publishEventPr = particle.publishEvent({ name: 'ActionChaudiere', data: event_data, auth: token });
publishEventPr.then(
function(data) {
if (data.body.ok) { console.log("Event published succesfully") }
particle.getVariable({ deviceId: '270043000447343232363230', name: 'bCmdChauffage', auth: token }).then(
function(data) {
document.getElementById("TxtCmdChauffage").innerHTML = "CmdChauffage="+data.body.result;
},
function(err) {
console.log('An error occurred while getting attrs:', err);
document.getElementById("TxtCmdChauffage").innerHTML = "Erreur lecture CmdChauffage";
});
},
function(err) {
console.log("Failed to publish event: " + err)
}
);
}
</script>
<form id="login-window">
<div class="w-25 form-group p-3">
<label for="InputLogin">Login</label>
<input type="login" class="form-control" id="InputLogin" aria-describedby="InputLogin" placeholder="login">
<label for="InputPassword">Password</label>
<input type="password" class="form-control" id="InputPassword" placeholder="Password">
</div>
</form>
<button type="submit" id="BoutonLogin" class="btn btn-primary" onclick="login()">Login</button>
<br><br>
<!--
<div class="card-deck w-100" >
-->
<div class="card text-white bg-info my-3" style="max-width: 50rem;">
<div class="card-header">chaudiere_9AYV</div>
<div class="card-body">
<div class="container">
<div class="row">
<div class="col-sm"><button type="button" class="btn btn-primary" onclick="Chauffage(1)">Allumer Chauffage()</button></div>
<div class="col-sm"><button type="button" class="btn btn-primary" onclick="Chauffage(0)">Arreter Chauffage()</button></div>
<div class="col-sm"><p id="TxtCmdChauffage"></p></div>
</div>
</div>
</div>
</div>
<div class="card text-white bg-info my-3" style="max-width: 50rem;">
<div class="card-header"><a href="https://emoncms.org/app/view" class="text-white">EmonPower</a></div>
<div class="card-body">
<div class="container">
<div class="row">
<div class="col-sm"><div id="classTxtImport"><p id="txtImportW"></p></div></div>
<div class="col-sm"><p id="TxtProdW"></p></div>
</div>
<div class="row">
<div class="col-sm"><p id="txtConsoW"></p></div>
<div class="col-sm"><div id="classTxtDivert"><p id="TxtDivertW"></p></div></div>
</div>
</div>
</div>
</div>
<div class="card text-white bg-info my-3" style="max-width: 50rem;">
<div class="card-header">Yaourtiere</div>
<div class="card-body">
<div class="container">
<div class="row">
<div class="col-sm"><p id="TxtTempYaourtiere"></p></div>
<div class="col-sm"><p id="TxtStatusYaourtiere"></p></div>
</div>
</div>
</div>
</div>
<!--
</div>
-->
</body>
</html>