-
Notifications
You must be signed in to change notification settings - Fork 0
/
fbLEDs.js
58 lines (43 loc) · 1.87 KB
/
fbLEDs.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
/*
swith off/on fritz box leds
Load additional npm modules 'netatmo-api' (config javascript adapter)
Usage: Provide fbIP and load additional npm modules 'xml2js' (config javascript adapter)
call set_led(state) function state is "1" to switch on and "2" to switch off.
*/
var parseString = require('xml2js').parseString;
var request = require('request');
var fbIP = "" /* ID Adress of your fritzbox */
function set_led(state) {
request('http://'+fbIP+'/login_sid.lua', function (error, response, body) {
if (!error && response.statusCode == 200) {
parseString(body, {
explicitArray: false,
mergeAttrs: true
},
function (err, result) {
if (err) {
log("Fehler: " + err);
} else {
if(result.SessionInfo.SID !="0000000000000000") {
var headers = {
'User-Agent': 'Super Agent/0.0.1',
'Content-Type': 'multipart/form-data'
}
var options = {
url: 'http://'+fbIP+'/system/led_display.lua?sid='+result.SessionInfo.SID,
method: 'POST',
headers: headers,
form: {'led_display': state,'apply': '','sid': result.SessionInfo.SID}
}
// Start the request
var xcode = request(options, function (error, response, body) { });
} else {
log.error("No seession ID");
}
}
});
} else {
log(error);
}
});
}