Starting with Plugboard V2

9 replies [Last post]
aivo
Offline
Tallinn, Estonia
Joined: 2 Mar 2011

Hello,

Should following script work - ie. is the syntax/spelling ok?  Or it should not with M8?  Have been trying with 279.14/1.0 and lcd does not change; see no errors and do not manage to snoop related xAP messages either.

Regards,
Aivo 


require("xap")

function send2lcd(lcdstr)
        local msg = string.format([[xap-header
{
target=dbzoo.livebox.controller:lcd
class=xAPBSC.cmd
}
output.state.1
{
id=*
text=%s
}]], lcdstr)
  delay(5)
  xap.sendShort(msg)
  os.exit()
end

function delay(duration)
  duration = duration or 1
  local time_to = os.time() + duration
  while os.time() < time_to do end
end

xap.init("dbzoo.lua.testlcd","FF00DD00","br0")
send2lcd("test123")
xap.process()

 

brett
Offline
Providence, United States
Joined: 9 Jan 2010
There is too much broken in that script

I'm not sure where to begin this is just broken in so many ways.

I suggest you have a look at the sample applets in /etc_ro_fs./plugboard/sample

As a script this would HOLD everything else to ransom. This delay() loop, which is a busy spin (extremely bad), will max the the HAH cpu at 100%..  If you want to send period events you need to use the Timer class and a callback.

As a skeleton you would so something like this - which will call the updateClock function every 10 seconds.

function updateClock()
end
xap.init(...)
xap.Timer(updateClock, 10):start()
xap.process()

aivo
Offline
Tallinn, Estonia
Joined: 2 Mar 2011
Lesson 1 learned

Ok Brett, such delay is bad, will take a note and try to make things more intelligent.

My effort with this test was to update lcd though - ie construct valid message and send it.  I have looked at new samples but clearly then .. have not managed to learn enough ;).

Stripping the sample to one below - if this should work standalone from lua - just one go to send2lcd and out?

Aivo


require("xap")

function send2lcd()
  xap.sendShort([[
xap-header
{
target=dbzoo.livebox.controller:lcd
class=xAPBSC.cmd
}
output.state.1
{
id=*
text=test123
}]])
end

xap.init("dbzoo.lua.testlcd","FF00DD00","br0")
send2lcd()

Brett: fixed above script to be the minimum required you don't need xap.process unless you are going to a receive xap events, or are using a Timer.

http://www.dbzoo.com/livebox/hah_xap_python#xap_lcd_clock  A Python version of your clock.

aivo
Offline
Tallinn, Estonia
Joined: 2 Mar 2011
Will test again with 328

Thank you Brett,

I was trying with this to produce script that would scroll info (1w temp, cc watts etc) on lcd.
For the moment however the minimal script above also is not changing lcd for me on 279.14/1.0.  Will try again when 328 chip arrives.

Kind regards,
Aivo

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
LCD Script

Hi Avio,

I've got this script running as a standalone Lua application, ie running lua clock2.lus.  You could use this as a starting point for your script and easily turn it into an Applet.

Regards

Karl

 

require("xap")

info = {version="0.02", description="HAH LCD Clock"}

-- Update the LCD every 5 seconds with the current time
function init()
    print("HAH LCD Clock")
    xap.Timer(doclock, 5):start()
end

function doclock()
    print("HAH LCD doclock")
    xap.send(string.format("xap-header\
    {\
    v=12\
    hop=1\
    source=dbzoo.lua.lcdclock\
    uid=FF00DD00\
    class=xAPBSC.cmd\
    target=dbzoo.livebox.Controller:lcd\
    }\
    output.state\
    {\
    id=*\
    text=%s\
    }\
    ",os.date("%H:%M:%S")))
end

xap.init("dbzoo.lua.lcdclock","FF00DD00","br0")
init()
xap.process()

aivo
Offline
Tallinn, Estonia
Joined: 2 Mar 2011
Strange but still same

Thank you Karl,

Also with this one lcd does not change for me, print lines appear normally.  What version of livebox are you running?

Regards,
Aivo

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
xFx Viewer

I'm running an alpha/beta version at the moment, I can't connect to it right now so can't give the specific version. 

Have you tried using the xFx viewer program to "see" the xAP messages on the LAN, http://www.xapautomation.org/index.php?title=xFx_Viewer.  This is a great tool to help troubleshoot problems. 

Have you been able to set the LCD using the web GUI interface?  I used this to see the xAP message, and built my code from there.

The reccuring print lines were used for troubleshooting the code, so I could see which code block was being executed, you would obviously take these out when the script is converted to an Applet.

 

Karl

aivo
Offline
Tallinn, Estonia
Joined: 2 Mar 2011
Good point

will do that.  I did try the xFx Viewer few weeks ago but did not manage to catch any messages, even when firewall off on pc.  Will give it another go and use really simple unmanaged bridge too if needed.

Yes, via webinterface lcd can be updated.

Regards,
Aivo

brett
Offline
Providence, United States
Joined: 9 Jan 2010
XfX viewer

Be aware if you are using V4 of xFxviewer you need to also have a HUB running otherwise you will get no data at all.   V3 did not have this requirement.  I tend to use V3 as I don't run any other xap programs on my windows box so starting a hub just so I can run V4 is really annoying.

aivo
Offline
Tallinn, Estonia
Joined: 2 Mar 2011
Got it working

on 279.14/1.0.  Needed was state.1 and also state value, i.e
output.state.1
    {
    state=on
    ..

Thanks,
Aivo

Hardware Info