BUG: Vera devices not backward compatible

I am one of the developers of the rfxcom plugin.

A new user has been having problems in running the rfxcom plugin on his Vera Lite device.
I have tracked the problem down to a missing lua bitw library.

On my Vera2 device with UI4, when I run the following code:

function some_test()
luup.log(“some_test2”)
luup.log( string.format(“%02X”, bitw.bnot(96)))
end

some_test()

I get this in my log:
50 04/25/12 21:10:51.406 luup_log:42: some_test2 <0x2c0c>
50 04/25/12 21:10:51.407 luup_log:42: FFFFFF9F <0x2c0c>

which is correct!

but the other user in UI5 gets the following result:

50 04/26/12 10:04:08.011 luup_log:0: some_test2 <0x2caa1680>
01 04/26/12 10:04:08.011 [31;1mLuaInterface::StartEngine failed run: 0 [string “function some_test()…”]:3: attempt to index global ‘bitw’ (a nil value) [0m <0x2caa1680>

Why do the devices have different lua libraries?

How do I resolve this incompatibility?

I’m not sure how the first code worked, I didn’t think the bit lib was pre-loaded.

There’s no call to [tt]require()[/tt] to load the Bit manipulation lib, so it should have errored out there as well. Have you tried manually loading it using:

bitw = require('bit')
and/or looking on the Vera fs for the library files to see where they are in the old and new environments, and if they can be loaded (not sure they why they would have loaded bit by default in older revs)

Well, I added the require function. on UI4 my result is the same:

08 04/28/12 11:29:04.273 JobHandler_LuaUPnP::HandleActionRequest device: 0 service: urn:micasaverde-com:serviceId:HomeAutomationGateway1 action: RunLua <0x2c0c>
08 04/28/12 11:29:04.273 JobHandler_LuaUPnP::HandleActionRequest argument Code=function some_test()
bitw = require(“bit”)
luup.log(“some_test2”)
luup.log( string.format(“%02X”, bitw.bnot(96)))
end

some_test() <0x2c0c>
50 04/28/12 11:29:04.367 luup_log:0: some_test2 <0x2c0c>
50 04/28/12 11:29:04.368 luup_log:0: FFFFFF9F <0x2c0c>

Can someone test this on Vera3 or Vera Lite running UI5?

The test to run is to go to MIOS Developers and test the following luup code. Then look into the log file to see the result:

function some_test()
bitw = require(“bit”)
luup.log(“some_test2”)
luup.log( string.format(“%02X”, bitw.bnot(96)))
end

some_test()

Thanks, Evert

Result for VeraLite, latest beta firmware:

08      04/28/12 11:39:13.190   JobHandler_LuaUPnP::HandleActionRequest argument Code=function some_test()
    bitw = require("bit")
    luup.log("some_test2")
    luup.log( string.format("%02X", bitw.bnot(96)))
end

some_test() <0x2f571680>
50      04/28/12 11:39:13.338   luup_log:0: some_test2 <0x2f571680>
01      04/28/12 11:39:13.339   ^[[31;1mLuaInterface::StartEngine failed run: 0 [string "function some_test()..."]:4: bad argument #2 to 'format' (integer exp
01      04/28/12 11:39:13.339   ^[[31;1mJobHandler_LuaUPnP::RunLua failed: function some_test()
    bitw = require("bit")
    luup.log("some_test2")
    luup.log( string.format("%02X", bitw.bnot(96)))
end

some_test()^[[0m <0x2f571680>

If it looks like a bug maybe it is a bug…

At http://bitop.luajit.org/index.html:

This was added because string.format("%x", x) fails for negative numbers on some platforms.

Indeed, the following does work:

function some_test()
    bitw = require("bit")
    luup.log("some_test2")
    luup.log( string.format("%02X", bitw.band(bitw.bnot(96),0x7fffffff)))
end
 
some_test()

and

function some_test()
    bitw = require("bit")
    luup.log("some_test2")
    luup.log( string.format("%02X", bitw.bnot(bitw.bnot(96))))
end
 
some_test()

Ok, thanks for the info. I can work around this incompatibly between UI4 en UI5.