-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun.js
36 lines (28 loc) · 1.08 KB
/
run.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
var OmiClient = require('./src/omi-client.js').OmiClient;
//var OmiClient = require('omi-client').OmiClient;
var inspect = require('util').inspect;
var host = 'ws://localhost:8080';
var omiClient = new OmiClient(host);
omiClient.once('ready', function() {
console.log("OmiClient connected to "+ host +'.');
var name = 'MyDevice';
var path = 'Your/Path/Things/'+name;
var ep = 'relay';
// ensure the instance in the O-MI node by issuing a write command
omiClient.write(path, ep, false);
// subscribe to changes from "MyDevice"
omiClient.subscribe(path, null, {}, function(ep, data, opts) {
console.log("Subscribe:", ep, data, opts);
});
// write ep to true, which should trigger subscription callback
setTimeout(() => { omiClient.write(path, ep, true); }, 500);
setTimeout(() => {
omiClient.read(path, ep, function(ep, value, opts) {
console.log('Read:', ep, value, opts);
});
}, 600);
});
omiClient.once('close', function() {
console.log("OmiClient websocket connection was lost.");
process.exit(1);
});