Twitter

51 replies [Last post]
Lawrencezarb
Offline
Joined: 7 Mar 2012

Hi, Can someone point me to a guide of how to setup of the twitter access, and the command structure for sending tweets, I cannot seem to get it to work!

Also a list of tweek examples would be useful to see what can be done thro twitter.

kevin9
Offline
Lincolnshire, United Kingdom
Joined: 24 May 2010
Start here...

This is the Twitter sestion of the wiki

http://www.dbzoo.com/livebox/twitter

And here are some scripts I use all the time on my box

http://www.homeautomationhub.com/content/twitter-scripts-messaging-schema

 

kevint

Lawrencezarb
Offline
Joined: 7 Mar 2012
Hi Kevint,I have setup the

Hi Kevint,

I have setup the account, but am not sutre how to format the twitter message to activate, for example one of the relays, and I don't know if my tweets are getting to the HAH box.

kevin9
Offline
Lincolnshire, United Kingdom
Joined: 24 May 2010
The first link I gave has an

The first link I gave has an example of what you send from twitter. Don't forget to include the command prefix

To see xAP traffic you need a viewer, I use a windows PC, so xFxViewer from

http://www.erspearson.com/xAP/xFx/viewer_main.htm

and to use that you need a hub, also from Edward

http://www.erspearson.com/xAP/xFx/hubs_main.htm

The hub must be running first.

There is also a xAPSnoop application which is similar but I have never used that runs directly on the Livebox

So, logged into my kevinshouse account I tweeted HAH Relay 1 on, where HAH is my command prefix. This results in a message as seen in Viewer

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

( Note my livebox has an instance of '1')

You need to know if this is working for you before you do much else

Next you need an Alias Interpreter, and I confess I haven't used this yet

The link in the twitter section goes to the wrong version of plugboard, but I know there is an example interpreter on your livebox in /etc_ro_fs/plugboard/samples called aliasApplet.lua

But hopefully someone who knows a bit more will jump in. we can record the steps and add the full example to the wiki.

kevint

 

 

 

 

Lawrencezarb
Offline
Joined: 7 Mar 2012
Ok, I've managed to get

Ok, I've managed to get XFXviewer working and can see the XAP-header as you describe when I send a tweet.

If I send "hah Relay 1 on" for example should I not see the status of Relay 1 on the webgui change from off to on.(Please note that I have not yet got any hardware installed on the livebox yet)

brett
Offline
Providence, United States
Joined: 9 Jan 2010
To answer your question YES

To answer your question YES if you refresh the web page.

Here is a diagram that explain how all the bit function together.

Twitter interaction

If somebody want to draw this up nicely in visio we can post it to the twitter wiki page.

I can hand draw faster than anybody could do this in a computer  :)

Brett

Lawrencezarb
Offline
Joined: 7 Mar 2012
Hi Brett,Thanks for the

Hi Brett,

Thanks for the diagram. Can you explain what is the plugboard. Is this something I have to add to make the relay work?

derek
Offline
Glasgow, United Kingdom
Joined: 26 Oct 2009
Rules and actions

The plugboard is described at http://www.dbzoo.com/livebox/hah_plugboard_v2

It allows you to register an interest in a specific xAP message (or set of messages) and will then perform an action when the message is spotted on your network. As well as actions based on messages, you can setup timers which also trigger actions.

Using the plugboard is a bit more complex than using some other HAH facilities, in that you need to write some scripts in Lua (or use a script that somebody else has written). You must also enable the plugboard itself (automation/assists tab on the UI).

It's very flexible and hugely powerful. Kinda like an http://www.ifttt.com/wtf for the HAH.

Derek

Lawrencezarb
Offline
Joined: 7 Mar 2012
sample scrips

I've tried to look into the sample scripts but when I ssh into the box and try to get into the sample folder I get a permission denied message

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Because the sample's are

Because the sample's are burnt into the firmware and can't be adjusted.  You need to copy them into /etc/plugboard before they can be executed and editted.

Brett

Lawrencezarb
Offline
Joined: 7 Mar 2012
Examples

Hi Brett,

I have manage dto copy 1 of the example scripts into the /etc/plugboard directory relay_auto_off.lua), but it has not effect.

On the webgui I change the state of Relay 1 to ON, but it remains on permanantly.

Do I have to do something else to activate the script?

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
Have you activated plugboard

Plugboard needs to be activated within the web GUI so that it loads and runs the scripts

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Why is your script called

Why is your script called relay_auto_off.lua ?  This will not be picked up all scripts should be of the form xxxApplet.lua - Are you running build 306 ?  Where did you get this example from?

Get yourself onto the latest release: http://www.dbzoo.com/livebox/upgrades_backups

Brett

Lawrencezarb
Offline
Joined: 7 Mar 2012
Hi Brett,Yes I did enable the

Hi Brett,

Yes I did enable the Plugboard on the webgui.

I am currently running version 306, and relay_auto_off.lua is what I found in the examples folder!

This is what is in the samples folder:-

# ls -l
-rw-r--r--    1 502      100           518 Jan  1  1970 alias1.lua
-rw-r--r--    1 502      100          1312 Jan  1  1970 alias2.lua
-rw-r--r--    1 502      100           406 Jan  1  1970 alias3.lua
-rw-r--r--    1 502      100           931 Jan  1  1970 alias4.lua
-rw-r--r--    1 502      100           483 Jan  1  1970 bind_relays.lua
-rw-r--r--    1 502      100           819 Jan  1  1970 cache_access.lua
-rw-r--r--    1 502      100           327 Jan  1  1970 clock.lua
-rw-r--r--    1 502      100           103 Jan  1  1970 expire_timer.lua
-rw-r--r--    1 502      100           553 Jan  1  1970 gcal_on_state.lua
-rw-r--r--    1 502      100           636 Jan  1  1970 relay_auto_off.lua
-rw-r--r--    1 502      100           472 Jan  1  1970 tweet_on_relay_off.lua
-rw-r--r--    1 502      100           358 Jan  1  1970 wild_match.lua

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Instead of posting a list of

Instead of posting a list of files you could also indicate where you are looking to save me asking.

Where are you looking ? Because in /etc_ro_fs/plugboard/samples you will not find that list of files.

I bet you upgraded from an OLD release and these are in /etc/plugboard/samples if this is the case then you might as well DELETE them all as they will NOT run as they are all v1 scripts which are not compatible with the new v2 plugboard engine.

Brett

Lawrencezarb
Offline
Joined: 7 Mar 2012
Hi Brett,Yes you are correct,

Hi Brett,

Yes you are correct, I did upgrade from and old version and that list is in /etc/plugboard/samples.

So are there examples that will work. I want to play around with the examples to try and learn how it works.

kevin9
Offline
Lincolnshire, United Kingdom
Joined: 24 May 2010
OK I have given this a go

I have copied aliasApplet.lua from /etc_ro_fs/plugboard/samples to /etc/plugboard.

I my case I copied it via my PC so I could modify the addresses to include  'instance',

ie

from dbzoo.livebox.Controller to dbzoo.livebox.1.Controller

and

dbzoo.livebox.Twitter to dbzoo.livebox.1.Twitter

(You may not need to do this editing)

Then I restarted plugboard from the WebGUI

From my 'kevinshouse' twitter account I sent the command

'HAH relay 1 on'    where HAH is  the command prefix

This produced a a xAP message of

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

which in turn produced a message from plugboard of


xap-header
{
uid=FF00D800
source=dbzoo.livebox.1.Plugboard
hop=1
class=xAPBSC.cmd
target=dbzoo.livebox.1.Controller:relay.1
v=12
}
output.state.1
{
id=*
state=on
}

turning the relay on and producing a xAPBSC.event message of

xap-header
{
v=12
hop=1
uid=FF00DB60
class=xAPBSC.event
source=dbzoo.livebox.1.Controller:relay.1
}
output.state
{
state=on
displaytext=Relay 1 on
}

Note that there is a small delay between entering the command in Twitter and the Livebox Twitter app picking it up.

Also I need to check wether the Twitter command is case sensitive

<edit> Be aware that the Livebox deletes the twitter command from the twitter account after it has been actioned. This is to allow the same command to be issued again, but it also means that there is no record in the twitter account of the commands sent <end edit>

I will write this up for the wiki later

 

kevint

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
In /etc_ro_fs/plugboard/samples

Check in above folder. 

Lawrencezarb
Offline
Joined: 7 Mar 2012
Yes, that is where the files

Ok, I dont know what happened but I think I was looking in the wrong folders, although I thought I was looking in the correct samples folder.

Now I have found the correct samples forlder with the xxxApplet.lua files, but when I try and copy one to the /etc_ro_fs/plugboard folder I get this message:-

# cp relay1AutoOffApplet.lua /etc_ro_fs/plugboard/
cp: cannot create '/etc_ro_fs/plugboard/relay1AutoOffApplet.lua': Read-only file system
#

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Lawrence given you are

Lawrence given you are struggling at this basic level I can give you the command however I feel you are going to struggle all the way along unless you are spoon fed the exact commands to type in.  If others are willing to help you then you may be in luck however this project is about discovery and learning for yourself, this is half the fun, the HAH isn't a turnkey system you need to do some work to enable various features.

I've looked at http://www.dbzoo.com/livebox/twitter wiki page and the EXACT command you need to enter is there in a large GREEN box that is hard to miss.  As you are having trouble reading let me reproduce it here for you.

cp /etc_ro_fs/plugboard/samples/aliasApplet.lua /etc/plugboard
/etc/init.d/xap restart plugboard

On those directories:

  • /etc is Read/Write
  • /etc_ro_fs as the name implied is READ-ONLY.

Brett

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
Your getting confused

You need to copy from etc_ro_fs/plugboard/samples to etc/plugboard

 

 

 

Try this and let us know how you get on

 

Garry

 

Just noticed Brett was replying as I was tying. one step ahead as usual ;)

kevin9
Offline
Lincolnshire, United Kingdom
Joined: 24 May 2010
How are you doing Lawrence?

How are you doiing with this Lawrence?, did my write up above make sense in the end?

kevint

 

Lawrencezarb
Offline
Joined: 7 Mar 2012
Hi Kevin9,As you can see from

Hi Kevin9,

As you can see from this thread I had diffculty getting even the samples to work.

got the samples working now, after all it was just me not reading the procedure correct and trying to copy the samples into the /etc_ro_fs/plugboard folder instead of the /etc/plugboard folder!!!

Now that I got it working I have to sit down and learn how the LUA scripting works.

I am surprised that I cannot find a script to do the simple task of the example shown of making the relays switch on and off via twitter.

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
Re-read the thread and wiki

Lawrence. You need the aliasApplet script which is in the examples folder. 

This has been mentioned a few times in this thread and on the wiki. Suggest you reread both to understand the workings before playing too much more. You will be able to do much more with it if you take time now to undestand how it all plugs together  

 

Garry

jim_lewis1
Offline
Joined: 12 May 2012
Also setting up Twitter

When I try to enable the Twitter service through the HAH browser I get an error that:

 

 

Authorisation has not been setup

 

What do I need to do to enable this?

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
?!?!

On the same hah web page there is a big authorise with twitter button!

It is also discussed on the wiki detailed in this post

 

Garry

jim_lewis1
Offline
Joined: 12 May 2012
As I say, pressing this just

As I say, pressing this just gives an error. I see the Wiki has now been modified to suggest using a different browser as this may be the cause of the problem.

whilst noobs quesitons may sometimes seem a bit dense even I couldn't overlook the button marked 'authorise with twitter'

The fact that I posted a question to this clearly points to it not working as expected so your answer was not very helpful.

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
Jim, I wasn't trying to be

Jim, I wasn't trying to be rude but your post says you tried to enable twitter NOT authorise it. From your post it looked as though you were enabling it before authorising the HAh. This would also explain your error message. 

If you are saying the authorisation step is not working then this will need looking at. 

I will take a look at the authorisation on my system when I get home. 

Maybe more detail in what you have tried and the exact results you got, with screenshot if poss, would help diagnose the issue without confusion Garry

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
All good for me

Jim I have just tried on my system and twitter authorisation works fine can you please confirm that you get transferred to the twitter website?, does the authorisation work okay at this stage? When do you see the error message is this when you click the enable button on the HAH web GUI? Garry

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Jim that wiki page regarding

Jim that wiki page regarding using a different browser for twitter authorisation hasn't been recently updated.  The section you are referring to regarding issues with IE8 was added on the 27-Jan-12.  I would find it unusual that twitter auth has suddenly broken.

Brett

jim_lewis1
Offline
Joined: 12 May 2012
Gary:No, I do not get

Gary:

No, I do not get transferred to the Twitter site when I press the button. (I will try a different browser)

Brett:

I maybe misinterpreted the message:

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

As I didn't know the expected behaviour of pressing the 'Authorise with Twitter' button.

After getting the error reported above I tried clicking on OAuth and that link worked ok, (takes me to the OAuth site) so I misinterpreted the message regarding browsers as to have something to do with this.

I now realise you mean if the 'Authorise with Twitter' button does not take you to the Twitter page try a different browser, (I think! is that what you mean?)

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
Yeah try a diff browser

As the link works ok for me

 

 

Garry

jim_lewis1
Offline
Joined: 12 May 2012
Twitter and Google Calendar

OK, using Chrome I was able to authenticate with Twitter.

However, I don't think that /etc/plugboard/samples exists

I tried using 'cd' to get to plugboard, but 'ls' only shows the plugboard.lua file.

IE I haven't got the alias file so I can't do the next step:

I set the command prefix to 'hah', so now in twitter if I type 'hah relay 1 on'

 

Similarly for Google Calendar. I have yet to see any evidence that the event is triggering properly.

I checked that the event was enetered as given and entered this directly as a message using xfx which switched the led as reuqired.

However, I have set an event and then waited while the time went past the start time and nothing happens.

If I change the password on google on the browser to something incorrect, then resave as the correct password will this force the HAH to poll Google Calendar and cache the next hour's events, or do I have to wait an hour after enetering any event before HAH polls Google Calendar?

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
Almost There

Hi Jim,

Well done on hanging in there and getting this far, it really is well worth it.

Looking at your post above, I think you may have missed typed the "cp" command, I've copied it below, from the wiki, for clarity.

cp /etc_ro_fs/plugboard/samples/aliasApplet.lua /etc/plugboard
/etc/init.d/xap restart plugboard

The first line copies the aliasApplet.lua script from the "/etc_ro_fs/plugboard/samples" folder, this part of the HAH filesystem that can't be updated, hence the "_ro_" at the start.  By placing it in the /etc/plugboard folder, and by the fact that is has "Applet.lua" at the end of it's name, it will be executed everytime the pluboard is started, usually at boot up.

The next line restarts the plugboard subsystem, saving you the hassle of a reboot.

This Alias script is key to Google as well, so once you've got this right it opens up lots of possibilities for you.

 

Karl

brett
Offline
Providence, United States
Joined: 9 Jan 2010
JimThe alias scripts and the

Jim

The alias scripts and the samples are mentioned:

Twitter and Google require an Alias interpreter as documented on these links:

The alias engine is discussed in more detail here:

Many of these questions have been asked before, which resulted in the wiki being updated, if you do a little searching you will find the answers.  Please take the time to read the documentation it may not be step by step but its certainly adequate if read. 

Brett

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
One other thing to bear in mind

The alias script works for rf and relays only. If you want to use this for arduino stuff. Eg LED switching you will need to modify the script. 

It is fairly intuitive if you take a look at it and relatively easy to modify to suit your needs

 

Garry

jim_lewis1
Offline
Joined: 12 May 2012
I am 100% positive I

I am 100% positive I entered:

cp /etc_ro_fs/plugboard/samples/aliasApplet.lua /etc/plugboard
/etc/init.d/xap restart plugboard

correctly, but I will try again tonight.

However, I'm still unclear as to why typing:

cd /etc/plugboard
ls

doesn't show me the /samples directory, should it not be possible to see this?


I must have made a boob at some point though as I now have

/plugbaord listed on /etc

again when I try to cd to this it gives an error

if i type:

rm plugbaord

will this remove this?


And finally, if I fail to find the aliasApplet.lua can I simply create it in vi in plugboard directory according to: http://www.dbzoo.com/livebox/twitter#alias_interpreter ?
DoubleSpeed
Offline
Bristol, United Kingdom
Joined: 31 Mar 2012
Using an FTP connection to my
Using an FTP connection to my box attached is screen shot showing the directory and the sample scripts, are you saying you are missing these completely? If so I can zip what’s on my box and email to you?
AttachmentSize
Capture.PNG 22.12 KB
garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
You need to get the Samples

You need to get the Samples from /etc_ro_fs/plugboard/samples. NOT /etc/plugboard/samples as these are version 1 (I think)

 

Brett, this has caught me out in the past. Any chance of removing them during an update to save confusion? Garry

jim_lewis1
Offline
Joined: 12 May 2012
Success!

Success!

not sure what I did wrong first time with the cp from /etc_ro_fs/plugboard/samples command, but it worked OK this time.

Once I'd remembered to restart plugboard I was able to tweet and see the message arrive in xfx viewer.

 

Now that I have been through the process I'm really impressed by what can be done and that all of this is provided free.

 

With regards to Google Calendar functionality, does the alias script mean that the HAH recognises Google Calendar events as twitter events and handles them in the same way?

 

(edited before seeing your response Garry)

I asked about how arduino:led funtionality could be added to the script. I've now seen there is the script section of the forum so will trawl that today.

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
The alias script handles

The alias script handles alias style xap messages regardless of their origin. 

 

Google and twitter send alias messages so hare handled. 

If I get chance tonight I could

Maybe have a go at adding led support for trial purposes, it wont be pretty but will function ;)

 

Garry

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
aliasApplet Modifications

Try modifying you /etc/plugboard/aliasApplet.lua script with the following, I've highlighted the additional code.  This hasn't been tested, and my programming skills are rubbish, but I think it will work.  Don't forget to restart the plugboard after saving the changes.

pat={
-- Add a new pattern match for the Arduino LED
    [rex.new("(led) (on|off)")]=function(m) led(m) end,

    [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
}

-- The Arduino LED function
function led(t)
  local addr1,state = unpack(t)
  bsc.sendState(string.format("dbzoo.livebox.Controller:%s",addr1),state)
end

function tweet(m)
  local msg = unpack(m)
  bsc.sendText("dbzoo.livebox.Twitter",msg)
end

This should enable you to send the commands "led on" or "led off", and if you're using the example from the wiki to control the LED, so the endpoint is "dbzoo.livebox.arduino:led", it should work, fingers crossed.

 


 

 

 

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
Karl, Thanks for this. Was

Karl,

 

Thanks for this. Was gonna have a go tonight but you beat me to it. 

Should the Controller not be Arduino though in the Bsc send state?

 

Cheers

 

Garry

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
You're Absolutely Right

Thanks Garry, I did mention that I can't program ;)  Does this looks better :-

-- The Arduino LED function
function led(t)
  local addr1,state = unpack(t)
  bsc.sendState(string.format("dbzoo.livebox.arduino:%s",addr1),state)
end

jim_lewis1
Offline
Joined: 12 May 2012
I wondered about that so I

I wondered about that so I must be beginning to understand the logic of these scripts!

 

Thanks for the help.

 

My wife is beginning to become slightly anxious about exactly what it is I plan to control around the house and how much wiring is goingto be involved!

 

Blinking an LED via Twitter or Google has so far elicted, 'that's nice dear'

 

(I wouldn't mind, but she trained as an instrumentaiton technician in France and worked for the ESA and Peugot at the start of her career. I guess my ham-fisted dabbling looks pretty unsophisticated to her eyes).

jim_lewis1
Offline
Joined: 12 May 2012
OK, I edited the

OK, I edited the aliasApplet.lua script as suggested, (with the correction).

 

Now when I send a tweet I see this message being relayed:

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

 

But no repsonse from the led

 

Any ideas where the error is?

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
Do you see the message sent

Do you see the message sent to xap serial that the applet should have sent!  The above message is from xap twitter and is present regardless of the script. 

You should see another message sent from plugboard to xap serial. I think!?

 

Garry

brett
Offline
Providence, United States
Joined: 9 Jan 2010
The modification you did to

The modification you did to the alias script does not talk to xap-serial directly it will send a xAPBSC.cmd with a state event to another LUA applet acting as the BSC/Serial gateway.

The gateway applet when it receives the xAPBSC.cmd with the state will communicate to xap-serial with a Serial.Send.  This is the same applet that is responsible for opening up the serial communication channel with the correct baud etc that you would have previously got working.

Brett

DoubleSpeed
Offline
Bristol, United Kingdom
Joined: 31 Mar 2012
Can you reboot HAH via
Can you reboot HAH via Twitter?
brett
Offline
Providence, United States
Joined: 9 Jan 2010
Sure.  Just create an alias

Sure.  Just create an alias entry for this in the aliasApplet

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
}

Brett

jim_lewis1
Offline
Joined: 12 May 2012
Still trying!

Hi again,

I haven't been able to get into this for a while and I'm struggling to remember what I had learned so far.

However, I did modify the aliasApplet.lua script as directed to allow messages to be sent to the Arduino and hence the LED.

Unfortunately it seems like this isn't working.

When I send a tweet I see the twitter message arive OK, but then nothing is done with it.

 

What could be the problem? and how should I troubleshoot it?

 

Thanks

Hardware Info