In the error tab:2020-06-02 17:27:00.438 Status: dzVents: Info: Opvragen Unifi: ------ Start internal script: Unifi:, trigger: "every minute"
2020-06-02 17:27:00.439 Status: dzVents: Debug: OpenURL: url = https://unifi/api/login
2020-06-02 17:27:00.439 Status: dzVents: Debug: OpenURL: method = POST
2020-06-02 17:27:00.439 Status: dzVents: Debug: OpenURL: post data = {"password":"...","username":"..."}
2020-06-02 17:27:00.439 Status: dzVents: Debug: OpenURL: headers = {["Content-Type"]="application/json"}
2020-06-02 17:27:00.439 Status: dzVents: Debug: OpenURL: callback = unifi_loggedin
2020-06-02 17:27:00.439 Status: dzVents: Info: ------ Finished Unifi
2020-06-02 17:27:00.440 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-06-02 17:27:01.049 Status: dzVents: Info: Opvragen Unifi: ------ Start internal script: Unifi: HTTPResponse: "unifi_loggedin"
2020-06-02 17:27:01.049 Status: dzVents: Debug: OpenURL: url = https://unifi/api/s/default/stat/sta
2020-06-02 17:27:01.050 Status: dzVents: Debug: OpenURL: method = GET
2020-06-02 17:27:01.050 Status: dzVents: Debug: OpenURL: post data = nil
2020-06-02 17:27:01.050 Status: dzVents: Debug: OpenURL: headers = nil
2020-06-02 17:27:01.050 Status: dzVents: Debug: OpenURL: callback = unifi_data
2020-06-02 17:27:01.050 Status: dzVents: Info: ------ Finished Unifi
2020-06-02 17:27:01.050 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-06-02 17:27:01.456 Status: dzVents: Info: Opvragen Unifi: ------ Start internal script: Unifi: HTTPResponse: "unifi_data"
2020-06-02 17:27:01.456 Status: dzVents: Debug: No HTTPResponse or not ok
2020-06-02 17:27:01.456 Status: dzVents: Info: ------ Finished Unifi
It looks like the login succeeds, but nothing gets returned.2020-06-02 17:27:01.377 Error: Error opening url: https://unifi/api/s/default/stat/sta
Any ideas?
The script that I use:
Code: Select all
local const = require "consts"
local urlUnifi = 'https://unifi/api'
local knownDevices = {
['80:58:f8:92:5f:6b'] = { idx=525, oui='Motorola'},
['dc:4f:22:76:73:57'] = { idx=526, oui='', hostname='OnePlus7T'},
}
return {
on = {
timer = {
'every minute'
},
httpResponses = { 'unifi_loggedin' , 'unifi_data' }
},
logging = {
level = domoticz.LOG_DEBUG,
marker = "Opvragen Unifi"
},
execute = function(dz, item)
_G.logMarker = _G.moduleLabel
local utils = dz.utils
if (item.isTimer or item.isDevice) then
dz.openURL({
url = urlUnifi .. '/login',
method = 'POST',
postData = {
['password'] = const.unifiPassword,
['username'] = const.unifiUser
},
callback = 'unifi_loggedin'
})
return;
end
if (not (item.isHTTPResponse and item.ok)) then
dz.log('No HTTPResponse or not ok', dz.LOG_DEBUG)
return;
end
if (item.trigger == 'unifi_loggedin') then
dz.openURL({
url = urlUnifi .. '/s/default/stat/sta',
method = 'GET',
callback = 'unifi_data'
})
return
end
lodash = dz.utils._
if (item.trigger == 'unifi_data') then
local json = utils.fromJSON(item.data)
if json == nil then
dz.log('item.data is nil ', dz.LOG_DEBUG)
return
end
print(json.data)
for i, item in ipairs(json.data) do
local device = knownDevices[item.mac]
if device ~= nil then
if device.idx ~= nil then
print(device.idx)
--dz.devices(device.idx). <----- TODO
end
else
dz.log('mac: ' .. item.mac .. ' - oui: ' .. item.oui .. '- hostname: ' .. item.hostname, dz.LOG_DEBUG)
end
end
end
end
}