-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample.js
65 lines (46 loc) · 1.35 KB
/
example.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
"use strict";
var quipu = require("./index.js");
var PIN = require("./myPINcode.js");
// initilize the device
var devices = {
modem: "/dev/serial/by-id/usb-HUAWEI_HUAWEI_HiLink-if00-port0",
sms: "/dev/serial/by-id/usb-HUAWEI_HUAWEI_HiLink-if02-port0"
};
quipu.handle("initialize", devices, PIN);
quipu.on("transition", function (data){
console.log("Transitioned from " + data.fromState + " to " + data.toState);
// send normal sms sms
quipu.sendSMS("1", "33671358943");
quipu.sendSMS("2", "33671358943");
});
// receiving normal SMS
quipu.on("smsReceived", function(sms){
console.log(sms);
});
// to send encoded, as sms don't like curly braces and other stuff
var parser = require("./parser.js")
parser.encode(devices)
.then(function(msg){
quipu.sendSMS(msg, "33671358943");
})
.catch(function(err){
console.log(err);
});
// and to decode use
quipu.on("smsReceived", function(sms){
parser.decode(sms.body)
.then(function(object){
console.log(object);
})
});
// spawning a 3G connexion and closing it after 30 seconds
quipu.handle("open3G");
setTimeout(function(){
quipu.handle("close3G");
}, 30000)
// open a reverse ssh tunnel towards "kerrigan" (must be set in your ~/.ssh/config)
quipu.handle("openTunnel", 2222, 9632, "kerrigan");
setTimeout(function(){
quipu.handle("closeTunnel");
}, 30000)
module.exports = quipu;