Posting to Twitter

1 reply [Last post]
BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010

Has anyone experienced any problems just posting an informational tweet, rather than a command tweet? 

I've written a Plugboard script to alert me when energy usage goes over a certain threshold, currently set low for testing.  However, more often than not, the tweet will never show up, after a bit of trouble shooting, I think the xap-twitter process may be deleting it as soon as it's sent it.  I've been through the Wiki a couple of times, and it does say that tweets will be deleted once actioned, but there is also an example of how to send a "Hello World" tweet.

Here is an example of the xAP messages that get generated when my script runs, and the script itself.  Perhaps a Forum area could be setup to share scripts in the future.

xAP-header
{
v=12
hop=1
uid=FF00D800
class=xAPBSC.cmd
source=dbzoo.livebox.Plugboard
target=dbzoo.livebox.Twitter
}
output.state.1
{
id=*
text=Energy usage is 891 kW
}


xap-header
{
v=12
hop=1
uid=FF00D900
class=alias
source=dbzoo.livebox.Twitter
}
command
{
text=Energy usage is 891 kW
}

 

 

And the Lua script

-- Tweet when CurrentCost reports more than 2kW

function init()
  register_source('dbzoo.livebox.CurrentCost:ch1.0', "dosource")
  watts_high_threshold = 600
  current_watts = 0
end

function tweet(msg)
   xap_send(string.format("xap-header\
{\
target=dbzoo.livebox.Twitter\
class=xAPBSC.cmd\
}\
output.state.1\
{\
id=*\
text=%s\
}", msg))
end

function dosource()
  if xAPMsg.class == "xAPBSC.event" then
        current_watts = xapmsg_getvalue("input.state","level")
        print (string.format("Current Watts = %s", current_watts))
        if tonumber(current_watts) > watts_high_threshold then
          tweet(string.format("Energy usage is %s kW", current_watts))
        end
  end
end

 

Any ideas or experience on this problem or using Twitter would be greatly appreciated.

 

Thanks

 

Karl

derek
Offline
Glasgow, United Kingdom
Joined: 26 Oct 2009
twitter ... unconditional delete

Karl,

Many thanks for sharing your script. Your idea of a 'script library' section on the forum is a good one. I'll get that done.

When we were testing the xap-twitter, the focus was firmly on 'control via twitter'. The ability to send a 'relay 1 on' style tweet is very nice. However, when a subsequent 'relay 1 on' tweet was sent (even after a few other tweets) twitter complained about a 'duplicate tweet'. The xap-twitter code was changed to cause the tweet to be deleted after it had been received.

I think that you are seeing a side effect of this. You don't want your tweet to be deleted.

So, xap-twitter can be modified to fix this. Perhaps 'command' tweets might start with a special character '!'  - then xap-twitter would know to only delete tweets that started with this character. You might be able to suggest another way to handle this one. Let us know what you think.

Two things to note.

The first is that Brett is awaiting a US style 15V DC PSU for his Livebox (and having just relocated, is hectically busy). My dev environment is at home & I'm not there (and Brett would fix this in 5mins, whilst I'd take ages). It might be a little while before this gets resolved ... that said, all the source code is available, so you might want to try a fix for yourself.

The second is that twitter will very soon require the use of OAuth for authentication http://countdowntooauth.com/. Currently, xap-twitter uses basic authentication. When twitter changes to OAuth, the xap-twitter will break. This is logged as an issue http://code.google.com/p/livebox-hah/issues/list  It will get fixed, the HAH google-calendar handler already uses OAuth. It will just take a little time to sort out.     

Meanwhile, I'll raise a new issue to track your report. Thanks again for taking the time to point this one out.

Derek.

Hardware Info