livebox:twitter

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
livebox:twitter [2012/03/16 17:06] – [xAP Twitter] brettlivebox:twitter [2012/05/29 10:59] (current) – [alias interpreter] brett
Line 32: Line 32:
 </code> </code>
  
-The commands you enter resolve the same way as the Google Calendar component (//See [[hah#calendar_aliases]]//) and require an [[hah_plugboard#alias_interpreter]] to resolve these into appropriate actions.+The commands you enter resolve the same way as the Google Calendar component (//See [[google_calendar#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.+{{:livebox:twitter_xap_process_v3.png|}} 
 + 
 +<note tip>To get up and running quickly you can use the sample provided on the box as a starting point.
 <code> <code>
-cp /etc_ro_fs/plugboard/samples/alasApplet.lua /etc/plugboard+cp /etc_ro_fs/plugboard/samples/aliasApplet.lua /etc/plugboard
 /etc/init.d/xap restart plugboard /etc/init.d/xap restart plugboard
-</code>+</code></note>
  
 ===== Sending tweets ===== ===== Sending tweets =====
Line 61: Line 63:
 text=Hello World text=Hello World
 } }
 +</code>
 +
 +===== alias interpreter =====
 +
 +An alias engine is supplied on the HAH as a sample to install this
 +<code>
 +# cp /etc_ro_fs/plugboard/samples/aliasApplet.lua /etc/plugboard
 +</code>
 +
 +This is how the default alias engine looks - You'll want to edit this as you add twitter and google calender command shortcuts.
 +<code lua>
 +--[[ 
 +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
 </code> </code>
  
  • livebox/twitter.1331917566.txt.gz
  • Last modified: 2012/03/16 17:06
  • (external edit)