xAP control for scripts

 

Hi guys, I have some scripting questions...

Following the examples, I have created a script to shutdown a PC running an ap to support shut down:

Member for

16 years 10 months

brett

16 years 2 months ago

The xAP spec requires that every header contains at least one block therefore this Calendar entry is invalid

xAP-header
{
target=dbzoo.livebox.ShutdownPC
source=GoogleCalendar
class=unknown
}

You can get away with something like

xAP-header
{
target=dbzoo.livebox.ShutdownPC
class=any
}
command
{
}

The source= will be automatically supplied so it can be omitted but you need a control block even if its empty. Personally I think I'd rework this so it was more like

xAP-header
{
target=dbzoo.livebox.PC:livingroom
class=xapBSC.cmd
}
output.state.1
{
id=*
text=shutdown
}

That way if you have multiple PC's they can each be designed.   Also then you could sent a broadcast to the target "dbzoo.livebox.PC:>" and it will shutdown ALL PC's if you code it right.

Your target in your LUA script is dbzoo.livebox.ShutdownPC but in the XML its dbzoo.livebox.shutdownPC

Watch out for case sensitivity.  All code should honour both but its worth mentioning all the same.

Brett

Member for

16 years 5 months

BodgeIT

16 years 2 months ago

OK, that vastly improved my GoogleCal message.

Still unable to send a similar message from xAPFlash on joggler but am now sure that's something with that app.

** Edit ** this was due to changes made in new beta5 and now works

I've now also created a script for the WOL function:

-- Script to wake up remote PC
--
-- Registers WOL PC service
function init()
  register_target("dbzoo.livebox.WOL:Home-PC", "dowake")
end

-- Sends http request to remote PC
function wake(mac)
os.execute(string.format("wol %s", mac))
xap_send("xap-header\
{\
target=dbzoo.livebox.ahscs5:OSD\
class=xAPBSC.cmd\
}\
output.state.1\
{\
id=*\
text='Wake up PC!'\
}\
")
end

function dowake()
  if xAPMsg.class == "xAPBSC.cmd" then
    mac = xapmsg_getvalue("output.state.1", "text")
    wake(mac)
  end
end  

I then send a message from Joggler:

xAP part looks like:

                    xap-header
                    {
                    v=13
                    hop=1
                    uid=FF.0738:0000
                    source=UKUSA.xAPFlash.ahscs5
                    target=dbzoo.livebox.WOL:Home-PC
                    class=xAPBSC.cmd
                    }
                    output.state.1
                    {
                    ID=*
                    text=00:0c:f1:e3:b7:84
                    }

Tested this and it works like a charm.

Not as neat as being able to just send a xap message to exposed WOL elements but should work...

Member for

16 years 10 months

brett

16 years 2 months ago

Have you looked at this section http://www.dbzoo.com/livebox/hah_plugboard#alias_interpreter and http://www.dbzoo.com/livebox/hah#calendar_aliases ?

You could build something that would work for both twitter AND google calendar in a single go.

Also from google calender instead of sending this LARGE customer xap message you would be able to just enter "WOL <MAC>" for example.    Using a MAC/HOST lookup table you could improve on this too.

See the alias4.lua interpreter code shipped on your livebox in /etc_ro_fs/plugboard/samples

Brett

Member for

16 years 5 months

BodgeIT

16 years 2 months ago

Created a sweet little script(see below) that's activated from a button on my Joggler!

With Kevin's new update, these 2 devices are a match made in heaven....almost.

Thanks though