Hi everyone, this is my first post and call for help to get Twitter fully working.
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.
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
but just remember it is 'Beta'.
Telnet into the HAH & run
/etc_ro_fs/update-dev hah-beta.dbzoo.com
Cheers,
Derek
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
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
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
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
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
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.
Thanks kema01 for the confirmation this is now working and thanks to Karl/Gary for the debug that helped me fix this quicker.
Brett
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? )
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
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?
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