-
Notifications
You must be signed in to change notification settings - Fork 0
/
tmo.js
103 lines (88 loc) · 2.78 KB
/
tmo.js
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
(function() {
window.Main = {};
Main.Page = (function() {
var mosq = null;
function Page() {
var _this = this;
mosq = new Mosquitto();
$('#connect-button').click(function() {
return _this.connect();
});
$('#disconnect-button').click(function() {
return _this.disconnect();
});
$('#subscribe-button').click(function() {
return _this.subscribe();
});
$('#unsubscribe-button').click(function() {
return _this.unsubscribe();
});
//TESTE DE FUNÇÃO QUE RECEBE O ESTADO DE UM SENSOR
// ----------------------------------
//aqui vemos que com strings voce envia irform~ções para as validações na automatização
$('#liga-output').click(function() {
var payload = "L";
var TopicPublish = $('#pub-topic-text')[0].value;
mosq.publish(TopicPublish, payload, 0);
});
$('#desliga-output').click(function() {
var payload = "D";
var TopicPublish = $('#pub-topic-text')[0].value;
mosq.publish(TopicPublish, payload, 0);
});
mosq.onconnect = function(rc){
var p = document.createElement("p");
var topic = $('#pub-subscribe-text')[0].value;
p.innerHTML = "Conectado ao Broker!";
$("#debug").append(p);
mosq.subscribe(topic, 0);
};
mosq.ondisconnect = function(rc){
var p = document.createElement("p");
var url = "ws://iot.eclipse.org/ws";
p.innerHTML = "A conexão com o broker foi perdida";
$("#debug").append(p);
mosq.connect(url);
};
mosq.onmessage = function(topic, payload, qos){
var p = document.createElement("p");
//cria elemento para mostrar retorno dos sensores
var acao = payload[0];
if (acao == 'L')
p.innerHTML = "<center><img src='ligado.png'><br>LIGADO</center>"
else
p.innerHTML = "<center><img src='desligado.png'><br>DESLIGADO</center>"
$("#status_io").html(p);
};
//escreve o estado do output conforme informação recebida
/*
var acao2 = playload[0];
var z = document.createElement("z");
//VARIAVEL QUE RECEBE ESTADO CHAR ENVIADO DA PLACA COM MQTT.PUBLISHER
if(acao2 == 'S')
z.innerHTML = "<center>Ligado</center>"
else (acao2 == 'F')
z.innerHTML = "<center><p>Desligado</p></center>"
$("#statusSensorTeste_io").html(z); */
}
Page.prototype.connect = function(){
var url = "ws://iot.eclipse.org/ws";
mosq.connect(url);
};
Page.prototype.disconnect = function(){
mosq.disconnect();
};
Page.prototype.subscribe = function(){
var topic = $('#sub-topic-text')[0].value;
mosq.subscribe(topic, 0);
};
Page.prototype.unsubscribe = function(){
var topic = $('#sub-topic-text')[0].value;
mosq.unsubscribe(topic);
};
return Page;
})();
$(function(){
return Main.controller = new Main.Page;
});
}).call(this);