-
Notifications
You must be signed in to change notification settings - Fork 0
/
renesas-fridge-dweet.js
89 lines (75 loc) · 2.68 KB
/
renesas-fridge-dweet.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
var allredon = {'led3':true,'led5':true,'led7':true, 'led9':true, 'led11':true, 'led13':true};
var allredoff = {'led3':false,'led5':false,'led7':false, 'led9':false, 'led11':false, 'led13':false};
var allyellowon = {'led12':true};
var allyellowoff = {'led12':false};
window.targetThing = "";
window.alertActive = false;
window.emailActive = false;
window.userEmailAddress = "";
window.servicerq1 = false;
window.servicerq2 = false;
window.key = "";
$.support.cors = true;
setTimeout(function(){
$('button#thingsubmit').click(function(e){
window.setThing($("#thingfield").val());
freeboard.setDatasourceSettings("DemoBoard", {"thing_id":window.targetThing});
$("#thingfield").prop('disabled', true);
$('button#thingsubmit').prop("disabled",true);
});
$('button#emailsubmit').click(function(e){
var emailaddy = $("#emailfield").val();
console.log(emailaddy);
window.setEmailAddress(emailaddy);
$("#emailfield").prop('disabled', true);
$('button#emailsubmit').prop("disabled",true);
});
},3000);
window.tipAlert = function(){
dweetio.dweet_for(window.targetThing+'-send', this.allredon, function(err, dweet){
});
freeboard.showDialog($("<div align='center'>Alert! Machine was tipped over. Send Repair Team.</div>"),"Alert","ok",null,function(){window.alertActive=false;dweetio.dweet_for(window.targetThing+'-send', this.allredoff, function(err, dweet){});});
window.alertActive = true;
}
window.setThing = function(thingname) {
window.targetThing = thingname;
}
window.setEmailAddress = function(email) {
window.userEmailAddress = email;
}
window.sendEmailAlert = function() {
window.emailActive = true;
if (window.userEmailAddress !== '') {
$.ajax({
type: "POST",
url: "https://mandrillapp.com/api/1.0/messages/send.json",
data: {
'key': window.key,
'message': {
'from_email': '[email protected]',
'to': [
{
'email': window.userEmailAddress,
'type': 'to'
}
],
'autotext': 'true',
'subject': 'RL78 Refrigeration Alert!',
'html': 'Temperature exceeded threshold.'
}
}
}).done(function(response) {
});
}
}
window.resetEmail = function() {
window.emailActive = false;
}
window.startServiceRequest = function() {
window.servicerq1 = true;
freeboard.showDialog($("<div align='center'>Service Request Detected! Please press Confirm</div>"),"Alert","Confirm",null,function(){dweetio.dweet_for(window.targetThing+'-send', {"led15":true}, function(err, dweet){});});
}
window.endServiceRequest = function() {
window.servicerq2 = true;
dweetio.dweet_for(window.targetThing+'-send', {"led15":false}, function(err, dweet){});
}