Table of Contents

xAP Twitter

This component allows you to tweet messages and control any xAP compliant device. The Livebox being such a device.

Due to the way in which Twitter works, you are not able to enter the same tweet twice. To work around this, the xap-twitter daemon will DELETE the tweet once it has processed it.

This means that you lose the audit trail of the commands you have sent. However, it has the benefit of giving active feedback that the command was accepted and processed. Only message beginning with the COMMAND PREFIX will be process by the daemon, and hence eligible for deletion.

Authentication is done via OAUTH so your password is not stored on the livebox.

If you are struggling to get OAUTH to work on when using IE8, try using another browser, eg Chrome

This will result in the following xAP message being transmitted.

xap-header
{
v=12
hop=1
uid=FF00D900
class=alias
source=dbzoo.livebox.Twitter
}
command
{
text=relay 1 on
}

The commands you enter resolve the same way as the Google Calendar component (See calendar_aliases) and require an alias_interpreter to resolve these into appropriate actions. The diagram below shows the entire process.

To get up and running quickly you can use the sample provided on the box as a starting point.
cp /etc_ro_fs/plugboard/samples/aliasApplet.lua /etc/plugboard
/etc/init.d/xap restart plugboard

Sending tweets

The xap-twitter process can also be used to send TWEETs to twitter. This is really useful if you have other scripts or processing running and you wish to record events. Twitter can be that event recording system to notify when something happens. As tweets can be relayed to your phone, this gives you the ability to remotely monitor events.

Sample payload to create the tweet “Hello World”

xAP-header
{
v=12
hop=1
uid=FF00DB00
class=xAPBSC.cmd
source=dbzoo.acme.test
target=dbzoo.livebox.twitter
}
output.state.1
{
id=*
text=Hello World
}

alias interpreter

An alias engine is supplied on the HAH as a sample to install this

# cp /etc_ro_fs/plugboard/samples/aliasApplet.lua /etc/plugboard

This is how the default alias engine looks - You'll want to edit this as you add twitter and google calender command shortcuts.

--[[ 
Alias interpreter
 
Use to perform actions based on xAP alias class messages emitted by
both xap-twitter and xap-googlecal
--]]
 
module(...,package.seeall)
 
require("xap")
require("xap.bsc")
require("string")
rex = require("rex_posix")
 
info={
   version="1.1", description="Alias Interpreter"
}
 
pat={
    [rex.new("(relay) ([1-4]) (on|off)")]=function(m) rfRelayCmd(m) end,
    [rex.new("(rf) ([0-9]+) (on|off)")]=function(m) rfRelayCmd(m) end,
    [rex.new("tweet (.*)")]=function(m) tweet(m) end,
    ["reboot"] = function() os.execute("reboot") end
}
 
function tweet(m)
  local msg = unpack(m)
  bsc.sendText("dbzoo.livebox.Twitter",msg)
end
 
function rfRelayCmd(t)
  local addr1,addr2,state = unpack(t)
  bsc.sendState(string.format("dbzoo.livebox.Controller:%s.%s",addr1,addr2),state)
end
 
function aliasEngine(frame)
  local alias = frame:getValue("command","text")
  for r,f in pairs(pat) do
      if type(r) == "string" then
         if r == alias then
            f()
         end
      else
        p={r:match(alias)}
        if #p > 0 then
            f(p)
        end
      end
  end
end
 
function init()
  local f = xap.Filter()
  f:add("xap-header","class","alias")
  f:add("command","text",xap.FILTER_ANY)
  f:callback(aliasEngine)
end