-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdefences.js
85 lines (73 loc) · 2.04 KB
/
defences.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
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var laser = new five.Led(9);
var detection = new five.Sensor("A0");
var isSecure = false;
var droneId = 1;
laser.on();
detection.scale(0, 1).on("change", function() {
var reading = !(this.value > 0.9);
if (isSecure !== reading) {
isSecure = reading;
if (!isSecure) {
sendEmail();
sendDrone(droneId);
}
}
});
});
function sendEmail() {
var nodemailer = require('nodemailer'),
fs = require('fs'),
data = fs.readFileSync('./smtp-config.json'),
smtpConfig;
smtpConfig = JSON.parse(data);
// create reusable transporter object using SMTP transport
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: smtpConfig.username,
pass: smtpConfig.password
}
});
// setup e-mail data with unicode symbols
var mailOptions = {
from: 'Ben Spoon <ben@benspoon.com.com>', // sender address
to: 'ben@benspoon.com', // list of receivers
subject: 'ZOMBIES ARE HERE', // Subject line
text: 'Dude, there are zombies. You should do something', // plaintext body
html: '<b>Dude, there are zombies. You should do something</b>' // html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
if(error){
return console.log(error);
}
console.log('Message sent: ' + info.response);
});
};
function sendDrone(sensorId) {
var RollingSpider = require("rolling-spider"),
temporal = require("temporal"),
drone = new RollingSpider();
drone.connect(function() {
drone.setup(function() {
temporal.queue([
{
delay: 0,
task: function () {
drone.flatTrim();
drone.startPing();
drone.takeOff();
}
},
{
delay: 500,
task: function () {
drone.land();
}
}]);
});
});
};