Twitter

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.

Member for

14 years 8 months

Lawrencezarb

14 years 8 months ago

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.

Member for

16 years 5 months

kevin9

14 years 8 months ago

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

 

 

 

 

Member for

14 years 8 months

Lawrencezarb

14 years 8 months ago

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)

Member for

16 years 10 months

brett

14 years 8 months ago

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

Member for

14 years 8 months

Lawrencezarb

14 years 8 months ago

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?

Member for

17 years

derek

14 years 8 months ago

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

Member for

14 years 8 months

Lawrencezarb

14 years 8 months ago

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

Member for

16 years 10 months

brett

14 years 8 months ago

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

Member for

14 years 8 months

Lawrencezarb

14 years 8 months ago

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?

Member for

15 years 7 months

garrydwilms

14 years 8 months ago

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

Member for

16 years 10 months

brett

14 years 8 months ago

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

Member for

14 years 8 months

Lawrencezarb

14 years 8 months ago

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

Member for

16 years 10 months

brett

14 years 8 months ago

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

Member for

14 years 8 months

Lawrencezarb

14 years 8 months ago

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.

Member for

16 years 5 months

kevin9

14 years 8 months ago

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

Member for

14 years 8 months

Lawrencezarb

14 years 8 months ago

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
#

Member for

16 years 10 months

brett

14 years 8 months ago

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

Member for

15 years 7 months

garrydwilms

14 years 8 months ago

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 ;)

Member for

16 years 5 months

kevin9

14 years 8 months ago

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

kevint

 

Member for

14 years 8 months

Lawrencezarb

14 years 8 months ago

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.

Member for

15 years 7 months

garrydwilms

14 years 8 months ago

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

Member for

14 years 6 months

jim_lewis1

14 years 6 months ago

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?

Member for

15 years 7 months

garrydwilms

14 years 6 months ago

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

Member for

14 years 6 months

jim_lewis1

14 years 6 months ago

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.

Member for

15 years 7 months

garrydwilms

14 years 6 months ago

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

Member for

15 years 7 months

garrydwilms

14 years 6 months ago

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

Member for

16 years 10 months

brett

14 years 6 months ago

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

Member for

14 years 6 months

jim_lewis1

14 years 6 months ago

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?)

Member for

15 years 7 months

garrydwilms

14 years 6 months ago

As the link works ok for me

 

 

Garry

Member for

14 years 6 months

jim_lewis1

14 years 6 months ago

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?

Member for

16 years 5 months

BoxingOrange

14 years 6 months ago

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

Member for

16 years 10 months

brett

14 years 6 months ago

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

Member for

15 years 7 months

garrydwilms

14 years 6 months ago

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

Member for

14 years 6 months

jim_lewis1

14 years 6 months ago

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 ?

Member for

14 years 7 months

DoubleSpeed

14 years 6 months ago

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?
Attachments
Capture.PNG (22.12 KB)

Member for

15 years 7 months

garrydwilms

14 years 6 months ago

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

Member for

14 years 6 months

jim_lewis1

14 years 6 months ago

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.

Member for

15 years 7 months

garrydwilms

14 years 6 months ago

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

Member for

16 years 5 months

BoxingOrange

14 years 6 months ago

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.

 


 

 

 

Member for

15 years 7 months

garrydwilms

14 years 6 months ago

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

Member for

16 years 5 months

BoxingOrange

14 years 6 months ago

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

Member for

14 years 6 months

jim_lewis1

14 years 6 months ago

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).

Member for

14 years 6 months

jim_lewis1

14 years 6 months ago

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?

Member for

15 years 7 months

garrydwilms

14 years 6 months ago

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

Member for

16 years 10 months

brett

14 years 6 months ago

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

Member for

14 years 7 months

DoubleSpeed

14 years 6 months ago

Can you reboot HAH via Twitter?

Member for

16 years 10 months

brett

14 years 6 months ago

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

Member for

14 years 6 months

jim_lewis1

14 years 4 months ago

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