forked from Frijol/calling-card
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (36 loc) · 1.05 KB
/
index.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
// Configuration variables
var config = require('./config.json');
// Require node modules
var twilio = require('twilio')(config.account_sid, config.auth_token);
// Require hardware
var tessel = require('tessel');
var rfidLib = require('rfid-pn532');
var rfid = rfidLib.use(tessel.port['A']);
rfid.on('ready', function () {
tessel.led[1].output(1);
console.log('RFID reader ready and waiting.')
rfid.on('data', function (cardData) {
console.log(cardData.uid);
sendText( config.num_to_call, config.twilio_num, cardData.uid + ' says hi');
});
});
rfid.on('error', function(err){
console.log('Error:', err);
});
function sendText(to,from,msg) {
console.log('Sending text...');
twilio.sendMessage({
to: to,
from: from,
body: msg
}, function(error, message) {
if (!error) {
console.log('Success! The SID for this SMS message is:');
console.log(message.sid);
console.log('Message sent on:');
console.log(message.dateCreated);
} else {
console.log('Oops! There was an error.', error);
}
});
}