I try to get some of the data in a virtual device. I had a normal lua script running but that doesn't work any more so I try to rewrite it into a Dzvents script. Hope someone can help me with this because I was searching for a simple example but could not find one that suits my need.
local ROOMBAIP = "192.168.178.185" -- Roomba IP Address
local ROOMBA_STATUS_IDX="1609" -- Roomba status IDX
local ROOMBA_BATTERY_STATUS_IDX="1611" -- Roomba battery charge status IDX
return {
active = true,
on = {
timer = { 'every 1 minutes' },
httpResponses = { 'Roomba' }
},
logging = {
level = domoticz.LOG_INFO,
marker = 'Roomba'
},
execute = function(domoticz, item)
if (item.isTimer) then
domoticz.openURL({
url = 'http://192.168.178.186/roomba.json',
method = 'GET',
callback = 'Roomba'
})
elseif (item.isHTTPResponse) then
if (item.ok) then -- success
if (item.isJSON) then
domoticz.log(response.r0.value)
domoticz.log('Roomba values checked', domoticz.LOG_INFO)
end
else
domoticz.log('Roomba values not JSON', domoticz.LOG_INFO)
end
domoticz.log('Roomba values not ok', domoticz.LOG_INFO)
end
end
}
But I can't figure out how i can get the values of each data fields.
Error: dzVents: Error: (2.4.23) Roomba: An error occurred when calling event handler Roomba
Error: dzVents: Error: (2.4.23) Roomba: /home/pi/domoticz/scripts/dzVents/scripts/Roomba.lua:35: attempt to index global 'rt' (a nil value)
When I manually put the json url in the browser I do get response.
_dzVents_ Error_ (2.4.23) Roomba_ Roomba values not JSON
This is because Roomba is not "well behaving". It should return 'application/json' in the 'Content-Type' field of the headers in the response if it returns in a json format. If it does, dzVents does already converts the json to a Lua table in the background (if you are interested; it is done in <domoticz dir>/dzvents/runtime/HTTPResponse.lua
So now you have do this conversion yourself. Try it with this.