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