-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.js
executable file
·49 lines (38 loc) · 1.25 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
42
43
44
45
46
47
48
49
var serialport = require("serialport")
, SerialPort = serialport.SerialPort;
function SendSMS(deviceID, phoneNumber){
var sp = new SerialPort("/dev/"+deviceID, {
parser: serialport.parsers.readline("\r"),
baudrate: 115200,
dataBits: 8, // this is the default for Arduino serial communication
parity: 'none', // this is the default for Arduino serial communication
stopBits: 1, // this is the default for Arduino serial communication
flowControl: false // this is the default for Arduino serial communication
});
sp.on("open", function () {
sp.on('data', function(data) {
var variavel = data.toString('utf8').trim();
console.log("Receive: " + variavel);
if(variavel == "+CMGS: 204") {
console.log("enviado com sucesso");
}
});
sp.on('close', function(a){
console.log("Close: " + a);
});
sp.on('error', function(a){
console.log("Close: " + a);
});
sp.write('AT+CMGF=1\r');
sp.write('AT+CMGS="'+phoneNumber+'"\r');
sp.write('SMS sent on: ' + new Date() + ' .');
sp.write(new Buffer([0x1a]));
});
}
var _deviceID = process.argv[2]
, _phoneNumber = process.argv[3];
if(!_deviceID || !_phoneNumber) {
module.exports = SendSMS;
} else {
SendSMS(_deviceID, _phoneNumber);
}