This repository was archived by the owner on Mar 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
96 lines (77 loc) · 2.6 KB
/
test.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
87
88
89
90
91
92
93
94
95
96
"use strict";
var WeMo = require('./lib/wemo.js');
var http = require('http');
var util = require('util');
var xml2js = require('xml2js');
var postbodyheader = [
'<?xml version="1.0" encoding="utf-8"?>',
'<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">',
'<s:Body>'].join('\n');
var postbodyfooter = ['</s:Body>',
'</s:Envelope>'
].join('\n');
var getcapabilities = {};
getcapabilities.path = '/upnp/control/bridge1';
getcapabilities.action = '"urn:Belkin:service:bridge:1#GetCapabilityProfileIDList"';
getcapabilities.body = [
postbodyheader,
'<u:GetCapabilityProfileIDList xmlns:u="urn:Belkin:service:bridge:1">',
'<DevUDN>%s</DevUDN>',
'</u:GetCapabilityProfileIDList>',
postbodyfooter
].join('\n');
var getcapabilitiesList = {};
getcapabilitiesList.path = '/upnp/control/bridge1';
getcapabilitiesList.action = '"urn:Belkin:service:bridge:1#GetCapabilityProfileList"';
getcapabilitiesList.body = [
postbodyheader,
'<u:GetCapabilityProfileList xmlns:u="urn:Belkin:service:bridge:1">',
'<CapabilityIDs>%s</CapabilityIDs>',
'</u:GetCapabilityProfileList>',
postbodyfooter
].join('\n');
var wemo = new WeMo();
wemo.on('discovered', function(device){
var dev = wemo.get(device);
console.log("%s - %s - %s:%s %s", device, dev.name, dev.ip, dev.port , dev.udn);
});
//var interval = setInterval(wemo.start.bind(wemo), 60000);
wemo.start();
setTimeout(function(){
var d = wemo.get("231442B01005F2-8418260000CA0456");
//var d = wemo.get("231442B01005F2-94103EA2B27803ED");
if (d) {
var postoptions = {
host: d.ip,
port: d.port,
path: getcapabilitiesList.path,
method: 'POST',
headers: {
'SOAPACTION': getcapabilitiesList.action,
'Content-Type': 'text/xml; charset="utf-8"',
'Accept': ''
}
}
var post_request = http.request(postoptions, function(res) {
var data = "";
res.setEncoding('utf8');
res.on('data', function(chunk) {
data += chunk;
});
res.on('end', function(){
xml2js.parseString(data,function(err, result) {
//u:GetCapabilityProfileListResponse
var list = result["s:Envelope"]["s:Body"][0]["u:GetCapabilityProfileListResponse"][0]["CapabilityProfileList"];
xml2js.parseString(list, function (err, result2){
console.log(util.inspect(result2, { depth: null }));
});
});
});
});
post_request.write(util.format(getcapabilitiesList.body, "10006,10008,30008,30009,3000A,10300,30301"));
post_request.end();
}
}, 11000);
setTimeout(function(){
console.log(util.inspect(wemo.get("231442B01005F2-8418260000CA0456").device, {depth: null}));
}, 12000);