-
Notifications
You must be signed in to change notification settings - Fork 0
/
relais.js
86 lines (65 loc) · 1.98 KB
/
relais.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
'use strict';
var Secucard = require('../secucard-connect-nodejs-client-lib');
var wpi = require( 'node-wiringpi' );
var secucard = new Secucard({
auth: {
client_id: '611c00ec6b2be6c77c2338774f50040b',
client_secret: 'dc1f422dde755f0b1c4ac04e7efbd6c4c78870691fe783266d7d6c89439925eb',
vendor: 'secucard',
uuid: '/vendor/secucard/relais/1',
refresh_token: "09acadd3044e42804941dcb94051250eae7d096d",
expires_in: 9000000
},
debug: true,
//environment: 'dev'
environment: 'prod'
});
wpi.pin_mode( 6, wpi.PIN_MODE.OUTPUT );
// Events
/*
onStompConnected
onStompDisconnect
onDeviceCodeAuthorizationPending
onDeviceCodeAuthorizationSuccess
onDeviceAuthorizationError
onDeviceAuthorizationSuccess
onMessage
*/
secucard.on('onMessage', function(msg) {
if (msg.body.type == 'SwitchRelais') {
_this.log.debug("SwitchRelais: " + msg.body.data.value);
wpi.digital_write( 6, msg.body.data.value );
// nach einer Sekunde wieder aus
setTimeout(function() {
wpi.digital_write( 6, wpi.WRITE.LOW );
}, 1000)
}
});
secucard.on('onStompDisconnect', function(msg) {
console.log("Got disconnected. Exit to get restarted");
setTimeout(function() {
wpi.digital_write( 6, wpi.WRITE.LOW );
process.exit();
}, 1000)
});
secucard.connect(function() {
var Auth = secucard.getController('auth');
// register Device every 30 seconds
setInterval(function() {
Auth.SessionsRefresh({pid: "me"}, function(err, headers, body) {
if (body.status == 'ok' && body.data.result == true) {
_this.log.debug('Auth.SessionsRefresh success');
} else {
_this.log.error('Auth.SessionsRefresh', body);
}
});
}, 30000)
});
process.on('SIGINT', function() {
console.log("Caught interrupt signal");
secucard.disconnect();
setTimeout(function() {
wpi.digital_write( 6, wpi.WRITE.LOW );
process.exit();
}, 1000)
})