- Home
- Deutsch
- ioBroker Allgemein
- Adapter: ioBroker.unifi
Adapter: ioBroker.unifi
-
hier der test mit linux
unifi enable {"meta":{"rc":"ok"},"data":[]}Enabling WiFi. {"meta":{"rc":"ok"},"data":[{"_id":"5d6512a897578401d1edd761","enabled":true,"security":"open","wep_idx":1,"wpa_mode":"wpa2","wpa_enc":"ccmp","usergroup_id":"5cadc7f73b6a3967dd7e5376","dtim_mode":"default","dtim_ng":1,"dtim_na":1,"minrate_ng_enabled":false,"minrate_ng_advertising_rates":false,"minrate_ng_data_rate_kbps":1000,"minrate_ng_cck_rates_enabled":true,"minrate_na_enabled":false,"minrate_na_advertising_rates":false,"minrate_na_data_rate_kbps":6000,"mac_filter_enabled":false,"mac_filter_policy":"allow","mac_filter_list":[],"bc_filter_enabled":false,"bc_filter_list":[],"group_rekey":3600,"name":"DragonRootGuest","wlangroup_id":"5cadc7f73b6a3967dd7e5377","fast_roaming_enabled":false,"schedule":[],"minrate_ng_mgmt_rate_kbps":1000,"minrate_na_mgmt_rate_kbps":6000,"minrate_ng_beacon_rate_kbps":1000,"minrate_na_beacon_rate_kbps":6000,"site_id":"5cadc7f53b6a3967dd7e5369","x_iapp_key":"cf930ad9a6750bd1d7c2f8676f775668","name_combine_enabled":true}]}root@iobroker59 09:28:00 /usr/local/bin > unifi disable {"meta":{"rc":"ok"},"data":[]}Disabling WiFi. {"meta":{"rc":"ok"},"data":[{"_id":"5d6512a897578401d1edd761","enabled":false,"security":"open","wep_idx":1,"wpa_mode":"wpa2","wpa_enc":"ccmp","usergroup_id":"5cadc7f73b6a3967dd7e5376","dtim_mode":"default","dtim_ng":1,"dtim_na":1,"minrate_ng_enabled":false,"minrate_ng_advertising_rates":false,"minrate_ng_data_rate_kbps":1000,"minrate_ng_cck_rates_enabled":true,"minrate_na_enabled":false,"minrate_na_advertising_rates":false,"minrate_na_data_rate_kbps":6000,"mac_filter_enabled":false,"mac_filter_policy":"allow","mac_filter_list":[],"bc_filter_enabled":false,"bc_filter_list":[],"group_rekey":3600,"name":"DragonRootGuest","wlangroup_id":"5cadc7f73b6a3967dd7e5377","fast_roaming_enabled":false,"schedule":[],"minrate_ng_mgmt_rate_kbps":1000,"minrate_na_mgmt_rate_kbps":6000,"minrate_ng_beacon_rate_kbps":1000,"minrate_na_beacon_rate_kbps":6000,"site_id":"5cadc7f53b6a3967dd7e5369","x_iapp_key":"cf930ad9a6750bd1d7c2f8676f775668","name_combine_enabled":true}]}root@iobroker59 09:29:23 /usr/local/bin >
-
@thewhobox sagte in Adapter: ioBroker.unifi:
body: JSON.stringify({ enabled }),
jetzt weiß ich wieder, warum ich mit json auf kriegsfuß stehe
09:36:40.055 info js2fs.0 Script script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2 modified in ioBroker, write to file 09:36:40.065 info javascript.1 Stop script script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2 09:36:40.065 info javascript.0 Stop script script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2 09:36:40.069 info javascript.2 Stop script script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2 09:36:40.080 info javascript.2 Start javascript script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2 09:36:40.081 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: starting test 09:36:40.081 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: start set wifi 09:36:40.081 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: need to login 09:36:40.081 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: registered 0 subscriptions and 0 schedules 09:36:40.311 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: login: got response: {"statusCode":200,"body":"{\"meta\":{\"rc\":\"ok\"},\"data\":[]}","headers":{"vary":"Origin","access-control-allow-credentials":"true","access-control-expose-headers":"Access-Control-Allow-Origin,Access-Control-Allow-Credentials","set-cookie":["unifises=4lIovxEqmKXvAF8JehI733XXQ6fSh1Se; Path=/; Secure; HttpOnly","csrf_token=4D3RfUt1GtDD4k6JXdNUcunJw5O0jqvu; Path=/; Secure"],"x-frame-options":"DENY","content-type":"application/json;charset=UTF-8","content-length":"30","date":"Wed, 28 Aug 2019 07:36:40 GMT","connection":"close"},"request":{"uri":{"protocol":"https:","slashes":true,"auth":null,"host":"192.168.178.157:8443","port":"8443","hostname":"192.168.178.157","hash":null,"search":null,"query":null,"pathname":"/api/login","path":"/api/login","href":"https://192.168.178.157:8443/api/login"},"method":"POST","headers":{"Content-Type":"application/json","content-length":40}}} 09:36:40.312 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: login: Login war erfolgreich! 09:36:40.312 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: set_cookies: 09:36:40.312 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: set_cookies: 09:36:40.312 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: login: Cookies: ["unifises=4lIovxEqmKXvAF8JehI733XXQ6fSh1Se","csrf_token=4D3RfUt1GtDD4k6JXdNUcunJw5O0jqvu"] 09:36:40.312 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: login: resolved 09:36:40.312 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: now setting wifi 09:36:40.312 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: got response 09:36:40.312 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: rejetced 09:36:40.312 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: resp: {} 09:36:40.322 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: rejected: StatusCodeError: 400 - "{\"meta\":{\"rc\":\"error\",\"msg\":\"api.err.IdInvalid\"},\"data\":[]}" 09:36:40.322 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: reject1: StatusCodeError: 400 - "{\"meta\":{\"rc\":\"error\",\"msg\":\"api.err.IdInvalid\"},\"data\":[]}" 09:36:40.322 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: getting status 09:36:42.072 info js2fs.0 Script file script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2 changed, also update in ioBroker 09:36:42.095 info javascript.2 Stop script script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2 09:36:42.117 info javascript.2 Start javascript script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2 09:36:42.117 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: starting test 09:36:42.118 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: start set wifi 09:36:42.118 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: need to login 09:36:42.118 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: registered 0 subscriptions and 0 schedules 09:36:42.421 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: login: got response: {"statusCode":200,"body":"{\"meta\":{\"rc\":\"ok\"},\"data\":[]}","headers":{"vary":"Origin","access-control-allow-credentials":"true","access-control-expose-headers":"Access-Control-Allow-Origin,Access-Control-Allow-Credentials","set-cookie":["unifises=EnoMzZ5FyglDTNPrZYGa2hvP16jewWiU; Path=/; Secure; HttpOnly","csrf_token=fAjfJm99u8hTqyKjEBfv7IRA4lZMILYO; Path=/; Secure"],"x-frame-options":"DENY","content-type":"application/json;charset=UTF-8","content-length":"30","date":"Wed, 28 Aug 2019 07:36:42 GMT","connection":"close"},"request":{"uri":{"protocol":"https:","slashes":true,"auth":null,"host":"192.168.178.157:8443","port":"8443","hostname":"192.168.178.157","hash":null,"search":null,"query":null,"pathname":"/api/login","path":"/api/login","href":"https://192.168.178.157:8443/api/login"},"method":"POST","headers":{"Content-Type":"application/json","content-length":40}}} 09:36:42.421 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: login: Login war erfolgreich! 09:36:42.421 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: set_cookies: 09:36:42.421 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: set_cookies: 09:36:42.421 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: login: Cookies: ["unifises=EnoMzZ5FyglDTNPrZYGa2hvP16jewWiU","csrf_token=fAjfJm99u8hTqyKjEBfv7IRA4lZMILYO"] 09:36:42.421 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: login: resolved 09:36:42.421 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: now setting wifi 09:36:42.421 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: got response 09:36:42.421 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: rejetced 09:36:42.421 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: resp: {} 09:36:42.429 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: rejected: StatusCodeError: 400 - "{\"meta\":{\"rc\":\"error\",\"msg\":\"api.err.IdInvalid\"},\"data\":[]}" 09:36:42.429 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: reject1: StatusCodeError: 400 - "{\"meta\":{\"rc\":\"error\",\"msg\":\"api.err.IdInvalid\"},\"data\":[]}" 09:36:42.429 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: getting status
-
@liv-in-sky Okay, zu dem Fehler finde ich leider auch nix im Netz. Hab es jetzt mal so angepasst wie in deinem verlinkten Skript.
Was mich wundert, dass nach "getting status" nix mehr kommt...
const request = require('request-promise-native').defaults({ rejectUnauthorized: false }); const unifi_username = "user"; const unifi_password = "pass"; const unifi_controller = "https://192.168.x.xx:xxxx"; const wifi_id = "dsa4fsda6g46fdsg984"; let cookies = []; let loggedIn = false; async function login() { return new Promise(async (resolve, reject) => { let resp = await request.post({ resolveWithFullResponse: true, url: unifi_controller + "/api/login", body: JSON.stringify({ username: unifi_username, password: unifi_password }), headers: { 'Content-Type': 'application/json' } }).catch((e) => { console.log("login: reject"), reject(e) }); if(resp != null) { console.log("login: Login war erfolgreich! " + ((resp.headers && resp.headers.hasOwnProperty("set-cookie")) ? "Mit Cookies":"Ohne Cookies")); if(resp.headers && resp.headers.hasOwnProperty("set-cookie")) { let set_cookies = resp.headers["set-cookie"]; for(i = 0; i < set_cookies.length; i++) { let cookie = set_cookies[i]; cookie = cookie.split(";")[0]; cookies.push(cookie); } } else { console.log("login: no cookies to set!") } loggedIn = true; resolve(); } else { console.log("login: rejected") reject("resp = null"); } }); } async function getStatus() { return new Promise(async (resolve, reject) => { console.log("nur mal so"); if(!loggedIn) await login().catch((e) => reject(e)); let resp = await request.get({ url: unifi_controller + "/api/s/default/rest/wlanconf/" + wifi_id, headers: { Cookie: cookies.join("; ") } }).catch((e) => { console.log("getStatus reject " + e); reject(e) }); console.log("got response " + JSON.stringify(resp)); if(resp != null && resp.statusCode == 200) { console.log("Status erfolgreich geholt!"); console.log(resp); let status = JSON.parse(resp); let wlanOn = status.data[0].enabled; console.log("WLAN ist: " + (wlanOn ? "an" : "aus")); resolve(wlanOn); } else { reject(JSON.parse(resp.body).meta.msg); } }); } async function logout() { return new Promise(async (resolve, reject) => { let resp = await request.get({ url: unifi_controller + "/logout", headers: { Cookie: cookies.join("; ") } }).catch((e) => reject(e)); if(resp != null) { console.log("Du bist nun ausgeloggt."); console.log(resp); resolve(); } else { reject("resp = null"); } }); } async function setWifi(enabled) { return new Promise(async (resolve, reject) => { console.log("setWifi: start set wifi"); if(!loggedIn) { console.log("need to login"); await login().catch((e) => reject(e)); } console.log("setWifi: now setting wifi"); let resp = request.post({ url: unifi_controller + "/api/s/default/upd/wlanconf/" + wifi_id, body: JSON.stringify({ enabled }), headers: { 'Content-Type': 'application/json', Cookie: cookies.join("; ") } }).catch((e) => { console.log("setWifi: rejected: " + e); reject(e) }); console.log("setWifi: got response") if(resp != null && resp.statusCode == 200) { console.log("setWifi: Wifi wurde erfolgreich " + (enabled ? "eingeschaltet" : "ausgeschaltet")); console.log(resp); resolve(); } else { console.log("setWifi: rejetced") console.log("resp: " + JSON.stringify(resp)); reject("msg: " + JSON.parse(resp.body).meta.msg); } }); } async function test() { console.log("starting test"); await setWifi(true).catch((e) => console.log("reject1: " + e)); console.log("getting status"); let wlan = await getStatus().catch((e) => console.log("reject2: " + e)); console.log("fin") console.log(wlan); } test()
-
@thewhobox moment noch - jetzt ist was passiert
-
@thewhobox
jeah -
scheint zu klappen - kann es ein und ausschalten09:55:42.324 info js2fs.0 Script script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2 modified in ioBroker, write to file 09:55:42.331 info javascript.2 Stop script script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2 09:55:42.337 info javascript.0 Stop script script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2 09:55:42.341 info javascript.1 Stop script script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2 09:55:42.352 info javascript.2 Start javascript script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2 09:55:42.353 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: starting test 09:55:42.353 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: start set wifi 09:55:42.353 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: need to login 09:55:42.353 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: registered 0 subscriptions and 0 schedules 09:55:42.672 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: login: Login war erfolgreich! Mit Cookies 09:55:42.673 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: now setting wifi 09:55:42.673 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: got response 09:55:42.673 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: rejetced 09:55:42.673 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: resp: {} 09:55:44.342 info js2fs.0 Script file script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2 changed, also update in ioBroker 09:55:44.360 info javascript.2 Stop script script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2 09:55:44.408 info javascript.2 Start javascript script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2 09:55:44.408 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: starting test 09:55:44.408 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: start set wifi 09:55:44.408 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: need to login 09:55:44.408 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: registered 0 subscriptions and 0 schedules 09:55:44.730 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: login: Login war erfolgreich! Mit Cookies 09:55:44.730 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: now setting wifi 09:55:44.730 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: got response 09:55:44.730 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: rejetced 09:55:44.730 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: resp: {}
-
@liv-in-sky
@thewhobox
moin, schon alle wieder fleißig...
Welches ist jetzt das komplette Script ? -
@dslraser 3 posts weiter oben
-
So hier nochmal mit Console Ausgaben nur wenn debug true ist.
@dslraser bringt er bei dir auch was nach "getting status"?const request = require('request-promise-native').defaults({ rejectUnauthorized: false }); const unifi_username = "user"; const unifi_password = "pass"; const unifi_controller = "https://192.168.x.xx:xxxx"; const wifi_id = "dsa4fsda6g46fdsg984"; let cookies = []; let loggedIn = false; let debug = false; function log(message) { if(debug) console.log(message); } async function login() { return new Promise(async (resolve, reject) => { let resp = await request.post({ resolveWithFullResponse: true, url: unifi_controller + "/api/login", body: JSON.stringify({ username: unifi_username, password: unifi_password }), headers: { 'Content-Type': 'application/json' } }).catch((e) => { log("login: reject"), reject(e) }); if(resp != null) { log("login: Login war erfolgreich! " + ((resp.headers && resp.headers.hasOwnProperty("set-cookie")) ? "Mit Cookies":"Ohne Cookies")); if(resp.headers && resp.headers.hasOwnProperty("set-cookie")) { let set_cookies = resp.headers["set-cookie"]; for(i = 0; i < set_cookies.length; i++) { let cookie = set_cookies[i]; cookie = cookie.split(";")[0]; cookies.push(cookie); } } else { log("login: no cookies to set!") } loggedIn = true; resolve(); } else { log("login: rejected") reject("resp = null"); } }); } async function getStatus() { return new Promise(async (resolve, reject) => { log("nur mal so"); if(!loggedIn) await login().catch((e) => reject(e)); let resp = await request.get({ url: unifi_controller + "/api/s/default/rest/wlanconf/" + wifi_id, headers: { Cookie: cookies.join("; ") } }).catch((e) => { log("getStatus reject " + e); reject(e) }); log("got response " + JSON.stringify(resp)); if(resp != null && resp.statusCode == 200) { log("Status erfolgreich geholt!"); log(resp); let status = JSON.parse(resp); let wlanOn = status.data[0].enabled; log("WLAN ist: " + (wlanOn ? "an" : "aus")); resolve(wlanOn); } else { reject(JSON.parse(resp.body).meta.msg); } }); } async function logout() { return new Promise(async (resolve, reject) => { let resp = await request.get({ url: unifi_controller + "/logout", headers: { Cookie: cookies.join("; ") } }).catch((e) => reject(e)); if(resp != null) { log("Du bist nun ausgeloggt."); log(resp); resolve(); } else { reject("resp = null"); } }); } async function setWifi(enabled) { return new Promise(async (resolve, reject) => { log("setWifi: start set wifi"); if(!loggedIn) { log("need to login"); await login().catch((e) => reject(e)); } log("setWifi: now setting wifi"); let resp = request.post({ url: unifi_controller + "/api/s/default/upd/wlanconf/" + wifi_id, body: JSON.stringify({ enabled }), headers: { 'Content-Type': 'application/json', Cookie: cookies.join("; ") } }).catch((e) => { log("setWifi: rejected: " + e); reject(e) }); log("setWifi: got response") if(resp != null) { log("setWifi: Wifi wurde erfolgreich " + (enabled ? "eingeschaltet" : "ausgeschaltet")); log(resp); resolve(); } else { log("setWifi: rejetced") log("resp: " + JSON.stringify(resp)); reject("msg: " + JSON.parse(resp.body).meta.msg); } }); } async function test() { log("starting test"); await setWifi(true).catch((e) => log("reject1: " + e)); log("getting status"); let wlan = await getStatus().catch((e) => log("reject2: " + e)); console.log("fin") console.log(wlan); } test()
-
was aber nervt - nicht script - es werden immer alle netzwerke aus und eingeschaltet - ist beim linux script auch - das scheint etwas mit unifi selbst zu tun zu haben
-
ich bin irgendwo nicht mit gekommen...?
das passiert beim letzten Script
javascript.0 2019-08-28 10:07:00.672 error at ContextifyScript.Script.runInContext (vm.js:59:29) javascript.0 2019-08-28 10:07:00.672 error at script.js.Heiko.Unifi.unifi_wifi:1:1 javascript.0 2019-08-28 10:07:00.672 error SyntaxError: Identifier 'log' has already been declared javascript.0 2019-08-28 10:07:00.672 error ^ javascript.0 2019-08-28 10:07:00.672 error const request = require('request-promise-native').defaults({ rejectUnauthorized: false }); javascript.0 2019-08-28 10:07:00.672 error script.js.Heiko.Unifi.unifi_wifi: script.js.Heiko.Unifi.unifi_wifi:1
-
muss leider nochmal fragen - wenn ich nur getStatus() anstatt test() aufrufe, sollte das funktionieren - es kommt kein WLAN ist an oder aus
10:05:22.860 info js2fs.0 Script script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2 modified in ioBroker, write to file 10:05:22.864 info javascript.1 Stop script script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2 10:05:22.865 info javascript.0 Stop script script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2 10:05:22.874 info javascript.2 Stop script script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2 10:05:22.886 info javascript.2 Start javascript script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2 10:05:22.886 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: starting test 10:05:22.886 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: start set wifi 10:05:22.886 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: need to login 10:05:22.886 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: registered 0 subscriptions and 0 schedules 10:05:23.174 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: login: Login war erfolgreich! Mit Cookies 10:05:23.174 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: now setting wifi 10:05:23.174 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: got response 10:05:23.174 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: Wifi wurde erfolgreich eingeschaltet 10:05:23.175 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: {} 10:05:23.175 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: getting status 10:05:23.175 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: nur mal so 10:05:23.183 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: got response "{\"meta\":{\"rc\":\"ok\"},\"data\":[{\"_id\":\"5d6512a897578401d1edd761\",\"enabled\":true,\"security\":\"open\",\"wep_idx\":1,\"wpa_mode\":\"wpa2\",\"wpa_enc\":\"ccmp\",\"usergroup_id\":\"5cadc7f73b6a3967dd7e5376\",\"dtim_mode\":\"default\",\"dtim_ng\":1,\"dtim_na\":1,\"minrate_ng_enabled\":false,\"minrate_ng_advertising_rates\":false,\"minrate_ng_data_rate_kbps\":1000,\"minrate_ng_cck_rates_enabled\":true,\"minrate_na_enabled\":false,\"minrate_na_advertising_rates\":false,\"minrate_na_data_rate_kbps\":6000,\"mac_filter_enabled\":false,\"mac_filter_policy\":\"allow\",\"mac_filter_list\":[],\"bc_filter_enabled\":false,\"bc_filter_list\":[],\"group_rekey\":3600,\"name\":\"DragonRootGuest\",\"wlangroup_id\":\"5cadc7f73b6a3967dd7e5377\",\"fast_roaming_enabled\":false,\"schedule\":[],\"minrate_ng_mgmt_rate_kbps\":1000,\"minrate_na_mgmt_rate_kbps\":6000,\"minrate_ng_beacon_rate_kbps\":1000,\"minrate_na_beacon_rate_kbps\":6000,\"site_id\":\"5cadc7f53b6a3967dd7e5369\",\"x_iapp_key\":\"cf930ad9a6750bd1d7c2f8676f775668\",\"name_combine_enabled\":true}]}" 10:05:24.876 info js2fs.0 Script file script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2 changed, also update in ioBroker 10:05:24.895 info javascript.2 Stop script script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2 10:05:24.919 info javascript.2 Start javascript script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2 10:05:24.919 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: starting test 10:05:24.919 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: start set wifi 10:05:24.919 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: need to login 10:05:24.919 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: registered 0 subscriptions and 0 schedules 10:05:25.205 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: login: Login war erfolgreich! Mit Cookies 10:05:25.205 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: now setting wifi 10:05:25.205 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: got response 10:05:25.205 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: setWifi: Wifi wurde erfolgreich eingeschaltet 10:05:25.206 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: {} 10:05:25.206 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: getting status 10:05:25.206 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: nur mal so 10:05:25.214 info javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN2: got response "{\"meta\":{\"rc\":\"ok\"},\"data\":[{\"_id\":\"5d6512a897578401d1edd761\",\"enabled\":true,\"security\":\"open\",\"wep_idx\":1,\"wpa_mode\":\"wpa2\",\"wpa_enc\":\"ccmp\",\"usergroup_id\":\"5cadc7f73b6a3967dd7e5376\",\"dtim_mode\":\"default\",\"dtim_ng\":1,\"dtim_na\":1,\"minrate_ng_enabled\":false,\"minrate_ng_advertising_rates\":false,\"minrate_ng_data_rate_kbps\":1000,\"minrate_ng_cck_rates_enabled\":true,\"minrate_na_enabled\":false,\"minrate_na_advertising_rates\":false,\"minrate_na_data_rate_kbps\":6000,\"mac_filter_enabled\":false,\"mac_filter_policy\":\"allow\",\"mac_filter_list\":[],\"bc_filter_enabled\":false,\"bc_filter_list\":[],\"group_rekey\":3600,\"name\":\"DragonRootGuest\",\"wlangroup_id\":\"5cadc7f73b6a3967dd7e5377\",\"fast_roaming_enabled\":false,\"schedule\":[],\"minrate_ng_mgmt_rate_kbps\":1000,\"minrate_na_mgmt_rate_kbps\":6000,\"minrate_ng_beacon_rate_kbps\":1000,\"minrate_na_beacon_rate_kbps\":6000,\"site_id\":\"5cadc7f53b6a3967dd7e5369\",\"x_iapp_key\":\"cf930ad9a6750bd1d7c2f8676f775668\",\"name_combine_enabled\":true}]}"
-
@dslraser Nein war mein Fehler gerade, jetzt nochmal:
@liv-in-sky laut Log hast du aber test aufgerufen? Hätte aber trotzdem nicht funktioniert, sollte jetzt aber gefixt sein.
const request = require('request-promise-native').defaults({ rejectUnauthorized: false }); const unifi_username = "user"; const unifi_password = "pass"; const unifi_controller = "https://192.168.x.xx:xxxx"; const wifi_id = "dsa4fsda6g46fdsg984"; let cookies = []; let loggedIn = false; let debug = true; function dlog(message) { if(debug) console.log(message); } async function login() { return new Promise(async (resolve, reject) => { let resp = await request.post({ resolveWithFullResponse: true, url: unifi_controller + "/api/login", body: JSON.stringify({ username: unifi_username, password: unifi_password }), headers: { 'Content-Type': 'application/json' } }).catch((e) => { dlog("login: reject"), reject(e) }); if(resp != null) { dlog("login: login war erfolgreich! " + ((resp.headers && resp.headers.hasOwnProperty("set-cookie")) ? "Mit Cookies":"Ohne Cookies")); if(resp.headers && resp.headers.hasOwnProperty("set-cookie")) { let set_cookies = resp.headers["set-cookie"]; for(i = 0; i < set_cookies.length; i++) { let cookie = set_cookies[i]; cookie = cookie.split(";")[0]; cookies.push(cookie); } } else { dlog("login: no cookies to set!") } loggedIn = true; resolve(); } else { dlog("login: rejected") reject("resp = null"); } }); } async function getStatus() { return new Promise(async (resolve, reject) => { dlog("nur mal so"); if(!loggedIn) await login().catch((e) => reject(e)); let resp = await request.get({ url: unifi_controller + "/api/s/default/rest/wlanconf/" + wifi_id, headers: { Cookie: cookies.join("; ") } }).catch((e) => { dlog("getStatus reject " + e); reject(e) }); dlog("got response " + JSON.stringify(resp)); if(resp != null && resp.meta.rc == "ok") { dlog("Status erfolgreich geholt!"); dlog(resp); let wlanOn = resp.data[0].enabled; dlog("WLAN ist: " + (wlanOn ? "an" : "aus")); resolve(wlanOn); } else { reject(JSON.stringify(resp)); } let wlanOn = resp.data[0].enabled; dlog("WLAN ist: " + (wlanOn ? "an" : "aus")); }); } async function dlogout() { return new Promise(async (resolve, reject) => { let resp = await request.get({ url: unifi_controller + "/dlogout", headers: { Cookie: cookies.join("; ") } }).catch((e) => reject(e)); if(resp != null) { dlog("Du bist nun ausgedloggt."); dlog(resp); resolve(); } else { reject("resp = null"); } }); } async function setWifi(enabled) { return new Promise(async (resolve, reject) => { dlog("setWifi: start set wifi"); if(!loggedIn) { dlog("need to login"); await login().catch((e) => reject(e)); } dlog("setWifi: now setting wifi"); let resp = request.post({ url: unifi_controller + "/api/s/default/upd/wlanconf/" + wifi_id, body: JSON.stringify({ enabled }), headers: { 'Content-Type': 'application/json', Cookie: cookies.join("; ") } }).catch((e) => { dlog("setWifi: rejected: " + e); reject(e) }); dlog("setWifi: got response") if(resp != null) { dlog("setWifi: Wifi wurde erfolgreich " + (enabled ? "eingeschaltet" : "ausgeschaltet")); dlog(resp); resolve(); } else { dlog("setWifi: rejetced") dlog("resp: " + JSON.stringify(resp)); reject("msg: " + JSON.parse(resp.body).meta.msg); } }); } async function test() { dlog("starting test"); await setWifi(true).catch((e) => dlog("reject1: " + e)); dlog("getting status"); let wlan = await getStatus().catch((e) => dlog("reject2: " + e)); console.log("fin") console.log(wlan); } test()
-
@thewhobox sorry falsches log
-
@liv-in-sky Ah okay. Wie gesagt, das hätte auch nicht klappen können^^
Versuch es mal mit dem neuen Skript von eins oben drüber. -
@thewhobox war das neuste script
-
in dem Log steht nun auch der Netzwerkname und auch das Passwort
28.8.2019, 10:18:18.764 [info ]: javascript.0 Stop script script.js.Heiko.Unifi.unifi_wifi 28.8.2019, 10:18:18.784 [info ]: javascript.0 Start javascript script.js.Heiko.Unifi.unifi_wifi 28.8.2019, 10:18:18.785 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: starting test 28.8.2019, 10:18:18.785 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: setWifi: start set wifi 28.8.2019, 10:18:18.785 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: need to login 28.8.2019, 10:18:18.785 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: registered 0 subscriptions and 0 schedules 28.8.2019, 10:18:19.083 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: login: login war erfolgreich! Mit Cookies 28.8.2019, 10:18:19.084 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: setWifi: now setting wifi 28.8.2019, 10:18:19.084 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: setWifi: got response 28.8.2019, 10:18:19.084 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: setWifi: Wifi wurde erfolgreich eingeschaltet 28.8.2019, 10:18:19.084 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: {} 28.8.2019, 10:18:19.084 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: getting status 28.8.2019, 10:18:19.084 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: nur mal so 28.8.2019, 10:18:19.123 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: got response "{\"meta\":{\"rc\":\"ok\"},\"data\":[{\"_id\":\"5d3c5be0bc96040011365fe5\",\"enabled\":true,\"security\":\"open\",\"wep_idx\":1,\"wpa_mode\":\"wpa2\",\"wpa_enc\":\"ccmp\",\"usergroup_id\":\"5d3b2323bc9604001132d2c5\",\"dtim_mode\":\"default\",\"dtim_ng\":1,\"dtim_na\":1,\"minrate_ng_enabled\":false,\"minrate_ng_advertising_rates\":false,\"minrate_ng_data_rate_kbps\":1000,\"minrate_ng_cck_rates_enabled\":true,\"minrate_na_enabled\":false,\"minrate_na_advertising_rates\":false,\"minrate_na_data_rate_kbps\":6000,\"mac_filter_enabled\":false,\"mac_filter_policy\":\"allow\",\"mac_filter_list\":[],\"bc_filter_enabled\":false,\"bc_filter_list\":[],\"group_rekey\":3600,\"name\":\"xxx Gäste\",\"is_guest\":true,\"x_passphrase\":\"xxx\",\"wlangroup_id\":\"5d3b2323bc9604001132d2c6\",\"schedule\":[],\"minrate_ng_mgmt_rate_kbps\":1000,\"minrate_na_mgmt_rate_kbps\":6000,\"minrate_ng_beacon_rate_kbps\":1000,\"minrate_na_beacon_rate_kbps\":6000,\"site_id\":\"5d3b231abc9604001132d2b8\",\"x_iapp_key\":\"0613db2263d118bc9e21936a202a964e\",\"fast_roaming_enabled\":false,\"no2ghz_oui\":true}]}"
-
@liv-in-sky Hmm okay, da fehlt mir das get resonse wie bei @dslraser
Ersetz mal die getStatus funktion
async function getStatus() { return new Promise(async (resolve, reject) => { dlog("nur mal so"); if(!loggedIn) await login().catch((e) => reject(e)); let resp = await request.get({ url: unifi_controller + "/api/s/default/rest/wlanconf/" + wifi_id, headers: { Cookie: cookies.join("; ") } }).catch((e) => { dlog("getStatus reject " + e); reject(e) }); dlog("got response " + JSON.stringify(resp)); if(resp != null && resp.meta && resp.meta.rc == "ok") { dlog("Status erfolgreich geholt!"); dlog(resp); let wlanOn = resp.data[0].enabled; dlog("WLAN ist: " + (wlanOn ? "an" : "aus")); resolve(wlanOn); } else { dlog("nicht ok...") reject(JSON.stringify(resp)); } let wlanOn = resp.data[0].enabled; dlog("WLAN ist: " + (wlanOn ? "an" : "aus")); }); }
-
-
@thewhobox sorry - hab beim kopieren das let cokkies... übersehen
so sieht es aus:
-
28.8.2019, 10:32:04.140 [info ]: javascript.0 Stop script script.js.Heiko.Unifi.unifi_wifi 28.8.2019, 10:32:04.168 [info ]: javascript.0 Start javascript script.js.Heiko.Unifi.unifi_wifi 28.8.2019, 10:32:04.168 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: starting test 28.8.2019, 10:32:04.168 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: setWifi: start set wifi 28.8.2019, 10:32:04.168 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: need to login 28.8.2019, 10:32:04.168 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: nur mal so 28.8.2019, 10:32:04.168 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: registered 0 subscriptions and 0 schedules 28.8.2019, 10:32:04.530 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: login: login war erfolgreich! Mit Cookies 28.8.2019, 10:32:04.552 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: login: login war erfolgreich! Mit Cookies 28.8.2019, 10:32:04.552 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: setWifi: now setting wifi 28.8.2019, 10:32:04.552 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: setWifi: got response 28.8.2019, 10:32:04.552 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: setWifi: Wifi wurde erfolgreich eingeschaltet 28.8.2019, 10:32:04.553 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: {} 28.8.2019, 10:32:04.553 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: getting status 28.8.2019, 10:32:04.553 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: nur mal so 28.8.2019, 10:32:04.582 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: got response "{\"meta\":{\"rc\":\"ok\"},\"data\":[{\"_id\":\"5d3c5be0bc96040011365fe5\",\"enabled\":true,\"security\":\"open\",\"wep_idx\":1,\"wpa_mode\":\"wpa2\",\"wpa_enc\":\"ccmp\",\"usergroup_id\":\"5d3b2323bc9604001132d2c5\",\"dtim_mode\":\"default\",\"dtim_ng\":1,\"dtim_na\":1,\"minrate_ng_enabled\":false,\"minrate_ng_advertising_rates\":false,\"minrate_ng_data_rate_kbps\":1000,\"minrate_ng_cck_rates_enabled\":true,\"minrate_na_enabled\":false,\"minrate_na_advertising_rates\":false,\"minrate_na_data_rate_kbps\":6000,\"mac_filter_enabled\":false,\"mac_filter_policy\":\"allow\",\"mac_filter_list\":[],\"bc_filter_enabled\":false,\"bc_filter_list\":[],\"group_rekey\":3600,\"name\":\"xxx Gäste\",\"is_guest\":true,\"x_passphrase\":\"xxx\",\"wlangroup_id\":\"5d3b2323bc9604001132d2c6\",\"schedule\":[],\"minrate_ng_mgmt_rate_kbps\":1000,\"minrate_na_mgmt_rate_kbps\":6000,\"minrate_ng_beacon_rate_kbps\":1000,\"minrate_na_beacon_rate_kbps\":6000,\"site_id\":\"5d3b231abc9604001132d2b8\",\"x_iapp_key\":\"0613db2263d118bc9e21936a202a964e\",\"fast_roaming_enabled\":false,\"no2ghz_oui\":true}]}" 28.8.2019, 10:32:04.582 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: nicht ok... 28.8.2019, 10:32:04.599 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: got response "{\"meta\":{\"rc\":\"ok\"},\"data\":[{\"_id\":\"5d3c5be0bc96040011365fe5\",\"enabled\":true,\"security\":\"open\",\"wep_idx\":1,\"wpa_mode\":\"wpa2\",\"wpa_enc\":\"ccmp\",\"usergroup_id\":\"5d3b2323bc9604001132d2c5\",\"dtim_mode\":\"default\",\"dtim_ng\":1,\"dtim_na\":1,\"minrate_ng_enabled\":false,\"minrate_ng_advertising_rates\":false,\"minrate_ng_data_rate_kbps\":1000,\"minrate_ng_cck_rates_enabled\":true,\"minrate_na_enabled\":false,\"minrate_na_advertising_rates\":false,\"minrate_na_data_rate_kbps\":6000,\"mac_filter_enabled\":false,\"mac_filter_policy\":\"allow\",\"mac_filter_list\":[],\"bc_filter_enabled\":false,\"bc_filter_list\":[],\"group_rekey\":3600,\"name\":\"xxx Gäste\",\"is_guest\":true,\"x_passphrase\":\"xxx\",\"wlangroup_id\":\"5d3b2323bc9604001132d2c6\",\"schedule\":[],\"minrate_ng_mgmt_rate_kbps\":1000,\"minrate_na_mgmt_rate_kbps\":6000,\"minrate_ng_beacon_rate_kbps\":1000,\"minrate_na_beacon_rate_kbps\":6000,\"site_id\":\"5d3b231abc9604001132d2b8\",\"x_iapp_key\":\"0613db2263d118bc9e21936a202a964e\",\"fast_roaming_enabled\":false,\"no2ghz_oui\":true}]}" 28.8.2019, 10:32:04.599 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: nicht ok... 28.8.2019, 10:32:04.599 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: reject2: "{\"meta\":{\"rc\":\"ok\"},\"data\":[{\"_id\":\"5d3c5be0bc96040011365fe5\",\"enabled\":true,\"security\":\"open\",\"wep_idx\":1,\"wpa_mode\":\"wpa2\",\"wpa_enc\":\"ccmp\",\"usergroup_id\":\"5d3b2323bc9604001132d2c5\",\"dtim_mode\":\"default\",\"dtim_ng\":1,\"dtim_na\":1,\"minrate_ng_enabled\":false,\"minrate_ng_advertising_rates\":false,\"minrate_ng_data_rate_kbps\":1000,\"minrate_ng_cck_rates_enabled\":true,\"minrate_na_enabled\":false,\"minrate_na_advertising_rates\":false,\"minrate_na_data_rate_kbps\":6000,\"mac_filter_enabled\":false,\"mac_filter_policy\":\"allow\",\"mac_filter_list\":[],\"bc_filter_enabled\":false,\"bc_filter_list\":[],\"group_rekey\":3600,\"name\":\"xxx Gäste\",\"is_guest\":true,\"x_passphrase\":\"xxx\",\"wlangroup_id\":\"5d3b2323bc9604001132d2c6\",\"schedule\":[],\"minrate_ng_mgmt_rate_kbps\":1000,\"minrate_na_mgmt_rate_kbps\":6000,\"minrate_ng_beacon_rate_kbps\":1000,\"minrate_na_beacon_rate_kbps\":6000,\"site_id\":\"5d3b231abc9604001132d2b8\",\"x_iapp_key\":\"0613db2263d118bc9e21936a202a964e\",\"fast_roaming_enabled\":false,\"no2ghz_oui\":true}]}" 28.8.2019, 10:32:04.599 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: fin 28.8.2019, 10:32:04.599 [info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: undefined