Help with callback in scripts
I've written a script to mirror a xap rf command on my livebox to a port on my raspi.
require "xap"
require "xap.bsc"
require("socket");
local switchoff="01427111937";
local switchon ="11427111937";
local myIP="172.16.1.164";
local myPort = 3000;
local sendTx
function init()
client=socket.tcp()
client:settimeout(0.5)
res, err = client:connect(myIP, myPort)
if not res and not res=="timeout" then
print("Error in connect: "..err)
os.exit()
end
print("success")
client:send("u", i, j)
f = xap.Filter()
f:add("xap-header", "source", "dbzoo.livebox.controller:rf.2")
f:add("xap-header","class","xAPBSC.event")
f:callback(switchplug)
end
function getdata()
local s, status, partial = client:receive('*l') --try to read all data
if status ~= "timeout" then
print(s)
end
end
function switchplug(frame)
sendTx = frame:getValue("output.state","state")
print(sendTx)
if sendTx == "on" then
client:send(switchon, i, j)
print(switchon)
else
client:send(switchoff, i, j)
print(switchoff)
end
end
xap.init("dbzoo.lua.tcptest","FF005A00" )
init()
xap.Timer(getdata, 6):start()
xap.process()
The script seems to work fine on the livebox but I expected to be able to run it on the Pi and have it respond to the xap function callback. Which of the xap programs needs to be running on the Pi to make this work?
if various modules are not running you can try running the start script manually
cd \etc\init.d
sudo sh ./xap start or service xap start
then ps -e
have you checked theres no case sensitive issues? i found i had to change a load of uppers to lower due to differences between my livebox and bbb port
Andrew
Hi allanayr
Does the it actually run or error out? whats the debug output?
could be that you that source is incorrect i.e dbzoo.livebox for me i changed my sources to dbzoo.beaglebone and so on...
in terms of running processes i would imagine xap-plugboard (identified as "lua") and xap-hub - have a look at the running process - ps -e
Andrew