07.01.2023, 22:29
(07.01.2023, 19:28)Erwin van der Zwart Wrote: Do you have require('user.vbus') at the start of the scripts that needs to use the user libs?
i changed line 9 in the script below from luavbus to vbus.
Code:
for _, searcher in ipairs(package.searchers or package.loaders) do
name = "luavbus"
local loader = searcher(name)
if type(loader) == 'function' then
package.preload[name] = loader
vbus = require (name)
break
end
name = "user.vbus"
local loader = searcher(name)
if type(loader) == 'function' then
package.preload[name] = loader
vbus = require (name)
break
end
end
log_level = WARN
if ( vbus == nil ) then
log ( "VBus modules not available")
end
vbus.new(nil, TCPIP, "vbus" )
vbus.remote_host = "192.168.0.188"
vbus.remote_port = "7053"
vbus.password = "vbus"
vbus:connect()
-- filter = { srcAddress = 0x7e11, dstAddress = 0x0010 }
-- filter = { command = 0x200 }
packets = vbus:waitData(filter, 30 )
if (packets ~= nil ) then
log( string.format ( "Returned %d packets", #packets ) )
for key, packet in pairs(packets) do
-- print ( string.format ( "Packet: %s", packet ) )
-- print ( packet:profileprint() )
if ( packet.profileData ~= nil) then
for k, data in pairs ( packet.profileData ) do
if ( data.factor < 1 ) then
log( string.format ( "Name %s Value %.02f %s", data.name, data.value, data.unit ) )
else
log( string.format ( "Name %s Value %d %s", data.name, data.value, data.unit ) )
end
end
end
end
else
log( "No packet!!!")
end
it seems it improved a bit because now the error logs show
Code:
User library Vbus:716: bad argument #1 to 'pairs' (table expected, got nil)
stack traceback:
[C]: in function 'pairs'
User library Vbus:716: in function 'readDevicesProfiles'
User library Vbus:233: in function 'waitData'