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
Last revisionBoth sides next revision
livebox:twitter [2012/01/27 20:29] – [Sending tweets] kevintlivebox:twitter [2012/05/29 10:55] – [alias interpreter] brett
Line 11: Line 11:
  
 Authentication is done via [[http://oauth.net/|OAUTH]] so your password is **not** stored on the livebox. Authentication is done via [[http://oauth.net/|OAUTH]] so your password is **not** stored on the livebox.
 +
 +<note tip>If you are struggling to get OAUTH to work on when using IE8, try using another browser, eg Chrome</note>
  
 {{:livebox:tweet.png|}} {{:livebox:tweet.png|}}
Line 30: 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. 
 + 
 +{{: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> 
 +cp /etc_ro_fs/plugboard/samples/aliasApplet.lua /etc/plugboard 
 +/etc/init.d/xap restart plugboard 
 +</code></note>
  
 ===== Sending tweets ===== ===== Sending tweets =====
Line 53: 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.txt
  • Last modified: 2012/05/29 10:59
  • by brett