xAP control for scripts

4 replies [Last post]
BodgeIT
Offline
London, United Kingdom
Joined: 10 Jun 2010

 

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:

-- Registers ShutdownPC service
function init()
  register_target("dbzoo.livebox.ShutdownPC", "shutdown")
end

-- Sends http request to remote PC
function shutdown()
os.execute("curl http://172.16.10.30:8000/?action=System.Shutdown")
  xap_send("xap-header\
{\
target=dbzoo.livebox.Twitter\
class=xAPBSC.cmd\
}\
output.state.1\
{\
id=*\
text='PC Shutdown!'\
}\
")
end

I have also set up a google cal event to activate this script:

This is the xAP header in the google cal entry:

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

Now as you know I'm trying to integrate the xAP Flash app into my home automation and I'd like to be able to activate this script from my Joggler.

Now I notice when the google cal event fires, I get this xAP message:

The following message caused an error during its processing.
The xAP message value is malformed. The block name contains one or more invalid characters
The message was received from 172.16.10.100:3078

------------
xAP-header
{
v=12
hop=1
uid=FF00DA00
class=unknown
source=dbzoo.livebox.GoogleCal
target=dbzoo.livebox.ShutdownPC
}
}

------------
The error that was generated is as follows:
The xAP message value is malformed
The block name contains one or more invalid characters

Source: xFx
The xAP message value is malformed
The block name contains one or more invalid characters
KCS.xAP.Framework.xAPException: The xAP message value is malformed
The block name contains one or more invalid characters
   at KCS.xAP.Framework.Message.xAPPairValue.ValidateValue()
   at KCS.xAP.Framework.Message.xAPMultiComponentValue..ctor(String value, Char seperator_char)
   at KCS.xAP.Framework.Message.xAPMessageBlock..ctor(String keyword)
   at KCS.xAP.Framework.Message.xAPMessageReader.ReadMessageBlockKeyword(xAPMessage message, String line)
   at KCS.xAP.Framework.Message.xAPMessageReader.ReadMessage()

But the script seems to fire.

My code for the xAPFlash config file stipulates that I need to include a little more in the header, so looks like this:

        <button NAME="Turn PC OFF">
            <gridX>2</gridX>
            <gridY>3</gridY>
            <posY>-10</posY>
            <posX>+10</posX>
            <visible>true</visible>
            <style>button60_off_.png</style>
            <textPrefix>PC_Off</textPrefix>
            <label>
                <fontsize>11</fontsize>
                <offset>-8</offset>
                <text>Shutdown PC</text>
            </label>
            <xAP>
                <schema>xAPBSC</schema>
                <uid>*</uid>
                <source>dbzoo.livebox.shutdownPC</source>
            </xAP>
            <mode>toggle</mode>
            <xapon>    
                xap-header
                {
                v=13
                hop=1
                uid=FF.0738:00
                source=UKUSA.Joggler.Controller
                target=dbzoo.livebox.shutdownPC
                class=unknown
                }
                output.state
                {
                }
            </xapon>
            <xapoff>    
            </xapoff>
        </button>

 

However this doesn't activate the script, so I was wondering if we could setup xAP on HAH for it to include plugboard scripts as xAP endpoints that follow the xAP schema?

Also I was also trying to figure out how to activate WOL entries via xAP, is this even possible?  I assume it is through some command entry but have spent some hours trying to suss it and have come up short.

Hoping you can nudge me in the right direction..

Cheers

Gary

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Thoughts on the matter

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

BodgeIT
Offline
London, United Kingdom
Joined: 10 Jun 2010
OK, that vastly improved my

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...

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Simpler

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

BodgeIT
Offline
London, United Kingdom
Joined: 10 Jun 2010
Already done it!

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

Hardware Info