-
Notifications
You must be signed in to change notification settings - Fork 6
/
test-device.js
70 lines (58 loc) · 1.35 KB
/
test-device.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
var Thing = require('Grow.js');
var inquirer = require('inquirer');
var _ = require('underscore')
var args = process.argv.slice(2);
var uuid = args[0];
var token = args[1];
var questions = [
{
type: 'input',
name: 'uuid',
message: 'Enter device UUID (you are given this when you create a new thing)',
},
{
type: 'input',
name: 'token',
message: 'Enter token',
},
];
if(_.isUndefined(uuid) || _.isUndefined(token)) {
inquirer.prompt(questions).then(function (answers) {
uuid = answers.uuid;
token = answers.token;
testDevice(uuid, token);
});
} else {
testDevice(uuid, token);
}
function testDevice (u, t) {
var testDevice = new Thing({
// PUT YOUR UUID AND TOKEN HERE OR SUPPLY THEM AS ARGUMENTS
uuid: u,
token: t,
component: 'TestDevice',
properties: {
state: 'off',
interval: 3000
},
start: function () {
setInterval(()=> {
testDevice.call('temp_data');
}, this.get('interval'));
},
turn_on: function () {
console.log('on');
testDevice.set('state', 'on');
},
turn_off: function () {
console.log('off');
testDevice.set('state', 'off');
},
temp_data: function () {
let temp = Math.random() * 100;
console.log(temp);
testDevice.emit('temperature', temp);
}
});
testDevice.connect();
}