Hi everyone, this is my first post and call for help to get Twitter fully working.

16 replies [Last post]
kema01
Offline
MAIDSTONE, United Kingdom
Joined: 8 Jul 2013

I have had the hah up and running for just over a week and half now and feel I have made some good progress, considering my very low level software knowledge.

I am very happy to report that I have tested the 4 relay outputs, 4 inputs, 3 RF outputs, 1 x 1 wire temperature sensor, clockapplet and Google Calendar without any major issues thanks to the level of expertise on the forum.

Twitter Problem. I can enter an Alias command (hah relay 1 on) directly into my new (hah) twitter account and this is received by the hah and relay 1 is operated. This tweet is sent to my old twitter account which I have set up to send me a SMS on receipt of a tweet from my new account. Hope this makes sense. The problem is I cannot generate a tweet directly from the hah. I have tried sending the script example Hello World below using xfx (cut and paste click send) to test, but nothing appears to happen. I am probably doing something obviously wrong to the trained eye.

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

}

My first hah challenge, is to get the hah via an applet to generate a tweet on activation of an input being triggered by either my burglar/fire alarm.

 

Any help would be much appreciated.

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
Me too

Hi, this appears to have stopped working recently.

I dont think this is anything youre doing wrong.

however, I've not been able to do any testing as am away from home and have been for a while. 

Garry

brett
Offline
Providence, United States
Joined: 9 Jan 2010
twitter buffer termination issue

I have to thank Karl for dropping me an email with some debug output that pin pointed why twitter has stopped working.  This happened when I had to rework the code as the 1.0 API was being deprecated and I had to upgrade to the later API's.

I've pushed a beta 309.8 which should sort this out - I've not tested this fully but it looks right to me.

For completeness here is the debug output with the offending line highlighted.

[inf][tcurl.c:277:getLatestTweet] Response from TWITTER '[{"created_at":"Tue Sep 10 20:28:22 +0000 2013","id":377528999301636097,"id_str":"377528999301636097","text":"Hah relay 1 off","source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":176537597,"id_str":"176537597"},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"symbols":[],"urls":[],"user_mentions":[]},"favorited":false,"retweeted":false,"lang":"en"}]'
[inf][tcurl.c:278:getLatestTweet] [{"created_at":"Tue Sep 10 20:28:22 +0000 2013","id":377528999301636097,"id_str":"377528999301636097","text":"Hah relay 1 off","source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":176537597,"id_str":"176537597"},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"symbols":[],"urls":[],"user_mentions":[]},"favorited":false,"retweeted":false,"lang":"en"}]
[inf][tcurl.c:306:getLatestTweet] Looking for id and text token
[inf][tcurl.c:311:getLatestTweet] Found ID token
[inf][tcurl.c:320:getLatestTweet] Found text token
[inf][tcurl.c:337:getLatestTweet] Tweet: 377528999301636097 Hah relay 1 offgle
[inf][tx.c:19:xapSend] send

Brett

kema01
Offline
MAIDSTONE, United Kingdom
Joined: 8 Jul 2013
Thank you

Brett many thanks for the fast response / fix for this problem and to Karl for passing on the debug.

Is the beta fix available for everyone, if yes can you please direct me to the location where it is located.

Many thanks again for your excellent support and resolution to this issue.

 

Kev.

derek
Offline
Glasgow, United Kingdom
Joined: 26 Oct 2009
Beta is available to all

but just remember it is 'Beta'.

Telnet into the HAH & run

/etc_ro_fs/update-dev hah-beta.dbzoo.com

Cheers,
Derek


BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
Twitter Not Sending

Although Brett had updated the code, and I can confirm the buffer error is fixed, the HAH is still unable to send Tweets.

Below is more debug output, for you to look at, in summary I think the problem lies with the Twitter authentication when sending a tweet, or the URL needs to be HTTPS instead of HTTP.  For those that are interested to get the debug output I went into the HAH web interface and disabled the Twitter service. I then telneted onto the HAH and issued the following command :- 

xap-twitter -i br0 -d 9

The "-d 9" sets the level of debug information, I usually start at a lower number, 4 or 5, and keep increasing it until I get the infomation that I need.
Brett, I hope this is enough to go on.  I was going to update and test the code myself, but I've just blown the PSU on my ESXi server, not sure when it's going to get fixed :(
Karl

dbg][parse.c:33:xapGetValueF] section=output.state.1 key=text

[dbg][filter.c:136:xapCompareFilters] match=0

[dbg][tcurl.c:265:getLatestTweet] Get tweet after this ID 8853522997059586

[dbg][tcurl.c:98:performGet] http://api.twitter.com/1.1/statuses/user_timeline.json?user_id=176537597...

[dbg][tcurl.c:27:clearCallbackBuffers] len: 678

[inf][tcurl.c:277:getLatestTweet] Response from TWITTER '[{"created_at":"Wed Sep 11 19:07:08 +0000 2013","id":377870945177726976,"id_str":"377870945177726976","text":"hah tweet Sending from Twitter","source":"web","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":176537597,"id_str":"176537597"},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"symbols":[],"urls":[],"user_mentions":[]},"favorited":false,"retweeted":false,"lang":"en"}]'

[inf][tcurl.c:278:getLatestTweet] [{"created_at":"Wed Sep 11 19:07:08 +0000 2013","id":377870945177726976,"id_str":"377870945177726976","text":"hah tweet Sending from Twitter","source":"web","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":176537597,"id_str":"176537597"},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"symbols":[],"urls":[],"user_mentions":[]},"favorited":false,"retweeted":false,"lang":"en"}]

[inf][tcurl.c:306:getLatestTweet] Looking for id and text token

[inf][tcurl.c:311:getLatestTweet] Found ID token

[inf][tcurl.c:320:getLatestTweet] Found text token

[inf][tcurl.c:339:getLatestTweet] Tweet: 377870945177726976 hah tweet Sending from Twitter

[inf][tx.c:19:xapSend] send

xap-header

{

v=12

hop=1

uid=FF00D900

class=alias

source=dbzoo.livebox.Twitter

}

command

{

text=tweet Sending from Twitter

}

 

[dbg][tcurl.c:27:clearCallbackBuffers] len: 678

[dbg][rx.c:23:readXapData] Rx xAP packet

xap-header

{

v=12

hop=1

uid=FF00D900

class=alias

source=dbzoo.livebox.Twitter

}

command

{

text=tweet Sending from Twitter

}

 

[dbg][parse.c:33:xapGetValueF] section=output.state.1 key=text

[dbg][filter.c:136:xapCompareFilters] match=0

[dbg][rx.c:23:readXapData] Rx xAP packet

xap-header

{

uid=FF00D800

source=dbzoo.livebox.Plugboard

hop=1

class=xAPBSC.cmd

target=dbzoo.livebox.Twitter

v=12

}

output.state.1

{

id=*

text=sending from twitter

}

 

[dbg][parse.c:33:xapGetValueF] section=output.state.1 key=text

[dbg][parse.c:42:xapGetValueF] found value=sending from twitter

[dbg][parse.c:33:xapGetValueF] section=xap-header key=class

[dbg][parse.c:42:xapGetValueF] found value=xAPBSC.cmd

[dbg][filter.c:53:xapFilterAddrSubaddress] filterAddr=xAPBSC.cmd addr=xAPBSC.cmd

[dbg][parse.c:33:xapGetValueF] section=xap-header key=target

[dbg][parse.c:42:xapGetValueF] found value=dbzoo.livebox.Twitter

[dbg][filter.c:53:xapFilterAddrSubaddress] filterAddr=dbzoo.livebox.Twitter addr=dbzoo.livebox.Twitter

[dbg][filter.c:136:xapCompareFilters] match=1

[dbg][parse.c:33:xapGetValueF] section=output.state.1 key=text

[dbg][parse.c:42:xapGetValueF] found value=sending from twitter

[inf][tcurl.c:349:sendTweet] sending from twitter

[dbg][tcurl.c:143:performPost] url=http://api.twitter.com/1.1/statuses/update.json

[dbg][tcurl.c:144:performPost] msg=status=sending from twitter

[dbg][tcurl.c:27:clearCallbackBuffers] len: 1925

[ntc][tcurl.c:194:performPost] ### response=401

[dbg][rx.c:23:readXapData] Rx xAP packet

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Damn Twitter for screwing

Damn Twitter for screwing around with the API's..  Karl thanks for that. I'll debug this tonight. It might well be I just need to change this to use https.

Brett

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Took me a while to sort out

Took me a while to sort out the sending side of things but build 309.9 should get you tweeting with the HAH as a service.
The sending is over https whilst the delete/get is over http
I'll come back and tidy this code up later for now it works and that is the main thing.

Damn both sending and receiving was broken - moving from the 1.0 API to the 1.1 API really screwed things didn't it?
Brett

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
Thanks for your work on this

Thanks for your work on this as Brett.

looking forward to getting this going again when I get back. Not touched HAH for a few months and starting to get withdrawal symptoms.

(think we may need to start a HAHanonymous group to help us folk that are afflicted with Home automation addiction syndrome )

:)

Garry

kema01
Offline
MAIDSTONE, United Kingdom
Joined: 8 Jul 2013
Confirmed it's working

Just a line to confirm this is now fully functional with beta build:309.9/3.4.

Many thanks

kev

derek
Offline
Glasgow, United Kingdom
Joined: 26 Oct 2009
Good work

Great to see everyone rallying around to get this sorted.

I recall that the twitter piece was absolutely solid before an API change at their end messed things up. Here's hoping that after their IPO ($10Bn ish) they might do better on the backwards compatibility front.

Kev, now that your scripts are working, please consider posting them in the 'Example Scripts' forum section. The more sample scripts that are availalbe, the easier it is for others to learn.

Derek.

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Thanks Kema01 and Karl/Gary

Thanks kema01 for the confirmation this is now working and thanks to Karl/Gary for the debug that helped me fix this quicker.

Brett

kema01
Offline
MAIDSTONE, United Kingdom
Joined: 8 Jul 2013
Derek I tested the

Derek I tested the functionality of twitter using the scripts on the hah wiki pages, I would love to be able to publish some code, unfortunately my current skill level is not even on the bottom rung of the ladder. 

I have tried to put together a script (please don’t fall over in fits of laughter) that will send me a tweet when an input is triggered as follows:-

xAP-header

{

class="xapbsc.event", 

source="dbzoo.livebox.controller:input.1

}

v=12

hop=1

uid=FF00DB00

class=xAPBSC.cmd

source=dbzoo.acme.test

target=dbzoo.livebox.twitter

}

output.state.1

{

id=*

text=Alarm triggered

}

 I know this is not correct and have pulled the information from the forum, I am getting confused as to if I need it to be an event or cmd amongst many other things.

What I would say to everyone who reads this is if, they have written some code no matter how small and insignificant they think it may be, please  please  please,  put them on the forum. This is how I am and after reading many requests on the forum, others will learn by looking at small snippets of code, making changes to tailor fit their own requirement and gradually build up their knowledge base of lua.

Can anyone suggest a beginner’s tutorial or equivalent guide to lua that is very close  to the scripts required  for the hah, I really need a very basic guide to get me started. 

Kev.

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
I know what you mean with

I know what you mean with example scripts.

i do something similar for my house alarm/smoke alarm. My attempt is shown below.

Probably could be done smarter but it works (or did do prior to the recent twitter issues, haven't updated my system to test the fix that Brett kindly did for us yet but It will work I'm sure!)

anyhow, might help..

 

ps this has a 4 sec debounce to ensure only "real" alarm states send not just momentary pulses on the inputs (which I do get for some reason? )

 

 

-- Tweet on House Alarm Triggered
module(...,package.seeall)
require("xap")
require("xap.bsc")
require("string")
info={
   version="1.0", description="House Alarm Twitter Report"
}
local Recipient = "@twitterrecipientaddhere"
function xAPTweetAlarmOn()
BSTadjust = 0
local oshour = os.date('%H')
local osmin = os.date('%M')
local osmonth = os.date('%m')
local osday = os.date('%d')
oshour = tonumber(oshour)
oshour = oshour + BSTadjust
local alarm_time_stamp = (osday.."-"..osmonth.." "..oshour..":"..osmin)
msg = string.format("%s %s at %s", Recipient, alarm_type, alarm_time_stamp)
bsc.sendText("dbzoo.livebox.Twitter",msg)
end
function action()
xap.Timer(logic, 4):start()
end
function logic(timerdebounce)
if inputstate == "on" then xAPTweetAlarmOn()
timerdebounce:delete()
end
timerdebounce:delete()
end
function stateregister()
inputstate = xap.getValue("input.state","state")
alarm_type = xap.getValue("input.state","displaytext")
end
function init()
   fa = xap.Filter()
   fa:add("xap-header","source","dbzoo.livebox.Controller:input.*")
   fa:add("xap-header","class","xAPBSC.event")
fa:add("input.state","state","on")
fa:callback(action)
fb = xap.Filter()
   fb:add("xap-header","source","dbzoo.livebox.Controller:input.*")
   fb:add("xap-header","class","xAPBSC.event")
fb:callback(stateregister)
end
garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
Re-reading your last post.

Kev,

 

After reading your post again it is evident you are very confused with the script writing.

please have another read through the wiki, especially the plugboard section.

basically the requirements of a script are (as I understand them):

1. a set of require statements so that we can use Brett's excellent libraries, amongst others.

2. an init() function which runs on startup, usually contains the filters which look for xap messages and then run a function when one received.( this is where you would tell the script to listen for events from your input of choice, or * for all inputs as per my script above)

3. One or more other functions that are called when the filter(s) conditions are met.

i will put together a very basic twitter post on input received script later so you can see the structure and modify it from there.

keep persevering it does come clearer with time, trust me i struggled big time at first.( still do in fact but am getting better). Plus you'll get more out of it if you can write scripts for your own individual requirements.

 

Garry

 

Update: basic script below, be aware I am away from by box so this is untested but I think its ok. Remeber if you want to use it, save it as something like "relay1tweetApplet.lua" in the plugboard directory. the Applet.lua bit is important.

-- Tweet on input 1 state on

module(...,package.seeall)
require("xap")
require("xap.bsc")
require("string")
info={
   version="1.0", description="Tweet on input 1 state on"
}

function tweet()
    local inputstate = xap.getValue("input.state","state")
    local msg = string.format("input 1 is %s", inputstate)
    bsc.sendText("dbzoo.livebox.Twitter",msg)
end

function init()
    f = xap.Filter()
    f:add("xap-header","source","dbzoo.livebox.Controller:input.1")
    f:add("xap-header","class","xAPBSC.event")
    f:add("input.state","state","on")
    f:callback(tweet)
end

kema01
Offline
MAIDSTONE, United Kingdom
Joined: 8 Jul 2013
Thanks again.

Garry

Just a line to thank you for both your post, I have not had a chance to give them a go yet, but will hopefully have time in the near future.

I am pleasantly surprised that the first one has the ability to ignore spurious false triggers.

I wish my brain was 45 years younger, then I may have a better chance of understanding lua.

Many thanks again for taking the time to respond to my request and the guidance you have given me.

 

Kev

allanayr
Offline
Ayr, United Kingdom
Joined: 25 Sep 2011
A quick question

I'm still using the 309 firmware release and, obviously, there is still a problem with twitter messages overwriting the previous message. Should we all move on to the 309.9 beta firmware or is it intended to release a new build with the twitter fix included?

 

Hardware Info