Problem with Action Twitter

Hi,

I still have issues with openHAB 2 & Twitter. I installed the action, configured everything, and everything works fine. But then, my smarthome simply stops twittering. The action ist up and running in bundle:list, but it does nothing.

So I try bundle:stop and bundle:start with the Twitter Action ID; now I get a stacktrace:

2017-07-19 12:33:53.443 [ERROR] [org.apache.felix.configadmin        ] - [org.openhab.core.scriptengine.action.ActionService, org.osgi.service.cm.ManagedService, id=330, bundle=199/mvn:org.openhab.action/org.openhab.action.twitter/1.10.0]: Unexpected problem updating configuration org.openhab.twitter
java.lang.IllegalStateException: consumer key/secret pair already set.
	at twitter4j.TwitterBaseImpl.setOAuthConsumer(TwitterBaseImpl.java:281)[199:org.openhab.action.twitter:1.10.0]
	at org.openhab.action.twitter.internal.TwitterActionService.createClient(TwitterActionService.java:93)[199:org.openhab.action.twitter:1.10.0]
	at org.openhab.action.twitter.internal.TwitterActionService.start(TwitterActionService.java:102)[199:org.openhab.action.twitter:1.10.0]
	at org.openhab.action.twitter.internal.TwitterActionService.updated(TwitterActionService.java:274)[199:org.openhab.action.twitter:1.10.0]
	at org.apache.felix.cm.impl.helper.ManagedServiceTracker.updated(ManagedServiceTracker.java:189)[3:org.apache.felix.configadmin:1.8.12]
	at org.apache.felix.cm.impl.helper.ManagedServiceTracker.updateService(ManagedServiceTracker.java:152)[3:org.apache.felix.configadmin:1.8.12]
	at org.apache.felix.cm.impl.helper.ManagedServiceTracker.provideConfiguration(ManagedServiceTracker.java:85)[3:org.apache.felix.configadmin:1.8.12]
	at org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.provide(ConfigurationManager.java:1461)[3:org.apache.felix.configadmin:1.8.12]
	at org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.run(ConfigurationManager.java:1417)[3:org.apache.felix.configadmin:1.8.12]
	at org.apache.felix.cm.impl.UpdateThread.run0(UpdateThread.java:141)[3:org.apache.felix.configadmin:1.8.12]
	at org.apache.felix.cm.impl.UpdateThread.run(UpdateThread.java:109)[3:org.apache.felix.configadmin:1.8.12]
	at java.lang.Thread.run(Thread.java:745)[:1.8.0_65]

Theres no way to get around this; even restarting openHAB 2 (or the whole system) does not help. The only workaround is:

  • uninstall Twitter Action
  • install Twitter Action
  • => immediately, and without auth process or something, Twitter is working fine again (“awaiting your tweets”)

This is far away from stable. What can I do to debug this behaviour?

Thanks for your ideas,
Marianne

So you have two problems:

  1. The action is up and running in bundle:list, but it does nothing.
  2. Stopping and restarting the bundle causes problems

For 2, I don’t see an easy fix. It appears to happen because the system didn’t destroy the Twitter singleton when stopping the bundle. (it also appears that there is no method for destroying the Twitter singleton, so that could be why)

For 1, more information is required. I assume that means your attempted tweets don’t show up in Twitter. Do you get any errors in the logs? What’s your item/sitemap/rule configuration?

Hi,

thank you for your answer. I’ll try to make it clearer:

Normally, my Twitter rules are triggered by cron; an example looks like this:

rule "Die hoechste Temperatur des Tages"
when
	Time cron "0 34 21 1/1 * ? *"
then
	var Hoechstwert = Wetter_Temperatur.maximumSince(now.withTimeAtStartOfDay).state
	sendTweet("Die hoechste gemessene Temperatur heute, am " +Heute_Datum.state.toString +", betrug " +Hoechstwert.toString +"°C.")
end

As you can see (my Twitter user is @sm4rth0me), this is basically working. I changed the “when” now to a virtual switch, so I can manually trigger the execution:

==> /var/log/openhab2/openhab.log <==
2017-07-20 09:24:04.918 [ERROR] [nhab.action.twitter.internal.Twitter] - Failed to send Tweet 'Die hoechste gemessene Temperatur heute, am 16.07.2017, betrug 20.90�C.' because of: 401:Authentication credentials (https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock is in sync.
message - Invalid or expired token.
code - 89

So it goes hand in hand with the one I reported in November (Problem using Twitter Binding - is it a bug?); when I reinstall the Action, it will work for a few days again (WITH the supposedly missing or incorrect token!).

Twitter Action: 1.10.0
openHAB 2: 2.1.0 release build (via package)

Tell me if you need further information; I would be interested in locating (even better: fixing) this.

Cheers,
Marianne

What system are you running on? How long exactly does it run between failures?

If you could get a debug log, that might help.

Hi,

[quote=“namraccr, post:4, topic:31894, full:true”]
What system are you running on?[/quote]
This is a Raspberry Pi 3 running openHABian (4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l GNU/Linux).
I have exactly the same behaviour on a second Raspberry Pi 3 running Raspbian and openHAB installed as a package.

It varies. From “three weeks without any issues” to “repaired it yesterday in die evening and now it’s broken again”.

I’d love to try, but it seems difficult?

openhab> log:set DEBUG org.openhab.action.twitter.internal.Twitter
openhab> log:get org.openhab.action.twitter.internal.Twitter
Logger                                      | Level
---------------------------------------------------
org.openhab.action.twitter.internal.Twitter | DEBUG
openhab> log:tail org.openhab.action.twitter.internal.Twitter
12:04:42.039 [ERROR] [nhab.action.twitter.internal.Twitter] - Failed to send Tweet 'Die höchste gemessene Temperatur heute, am 16.07.2017, betrug 24.00°C.' because of: 401:Authentication credentials (https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock is in sync.
message - Invalid or expired token.
code - 89

Seems exactly the same for me as the non-DEBUG output?

Cheers,
Marianne

Try this instead:

log:set DEBUG org.openhab.action.twitter
log:set DEBUG twitter4j

There’s very little debug logging in the twitter action itself, but we may get something from the underlying twitter4j library.

It doesn’t seem to be very chatty :frowning:

2017-07-21 23:35:10.424 [DEBUG] [org.openhab.action.twitter          ] - ServiceEvent REGISTERED - {org.openhab.core.scriptengine.action.ActionService, org.osgi.service.cm.ManagedService}={service.pid=org.openhab.twitter, component.name=org.openhab.action.twitter.action, component.id=197, service.id=327, service.bundleid=199, service.scope=bundle} - org.openhab.action.twitter
2017-07-21 23:35:10.458 [DEBUG] [org.openhab.action.twitter          ] - BundleEvent STARTING - org.openhab.action.twitter
2017-07-21 23:35:10.465 [DEBUG] [on.twitter.internal.TwitterActivator] - Twitter action has been started.
2017-07-21 23:35:10.471 [DEBUG] [org.openhab.action.twitter          ] - BundleEvent STARTED - org.openhab.action.twitter
2017-07-21 23:35:10.667 [INFO ] [witter.internal.TwitterActionService] - TwitterAction has been successfully authenticated > awaiting your Tweets!
2017-07-21 23:37:03.247 [ItemCommandEvent          ] - Item 'TwitterTest' received command ON
2017-07-21 23:37:03.258 [ItemStateChangedEvent     ] - TwitterTest changed from OFF to ON
2017-07-21 23:38:57.651 [ERROR] [nhab.action.twitter.internal.Twitter] - Failed to send Tweet 'Die höchste gemessene Temperatur heute, am 16.07.2017, betrug 21.30°C.' because of: 401:Authentication credentials (https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock is in sync.

Pfffff. No further ideas for the moment :slight_smile:

Same here. The twitter4j library we’re using is really old at this point. Could be it’s not doing any logging.

Weird. After a shutdown and restart of OH, I now get lots of DEBUG output.

12:00:00.203 [DEBUG] [itter4j.internal.http.HttpClientImpl] - X-Twitter-Client-Version: 3.0.5
12:00:00.203 [DEBUG] [itter4j.internal.http.HttpClientImpl] - X-Twitter-Client-URL: http://twitter4j.org/en/twitter4j-3.0.5.xml
12:00:00.203 [DEBUG] [itter4j.internal.http.HttpClientImpl] - X-Twitter-Client:Twitter4J

Simply after doing

log:set DEBUG etc...

I got absolutely nothing regarding DEBUG messages. So I restarted openHAB, and the result was my posting yesterday… I’ll reboot the whole system now. (But this is not how it’s intended to be, is it?)

No, it’s not the way it’s supposed to work.

But it seems there are a number of things currently that take a lot of undoing and restarting.

Glad to hear that it’s not only my personal notion!
Restart in progress…

Okay - but even complete restart has no effect :frowning:
I uninstalled now the action again, removed all twitter.* in /var/lib/openhab2, installed it again. Authentication succeeds, twitter.pin => twitter.token, all is fine: “awaiting your tweets”. But

  • still no usable DEBUG log and
  • still no tweets

What could be broken? Apart from that, the whole system is running fine, including HomeKit integration…

My last idea at the moment is to check your Pi to verify it has the correct time.

If the system’s clock drifts too far from Twitter’s, calls could fail because of that.

Each host in my network gets a clean ntpd setup via puppet… I double-checked that, but ntpd is running fine, and date and time are verified :frowning:

I suspect this error causes from anywhere in /var/lib/openhab2
I purged openhab2 package, /etc/openhab2, /var/lib/openhab2, /srv/openhab2 and everything around. Then I reinstalled, and the only thing I re-used from backup where the persistence files in /var/lib/openhab2/persistence and items, rules and sitemaps.

For now, Twitter action is working fine again - let’s see for how long. Whatever I try, DEBUG messages are still not available.

Will close this issue now because I’m off for vacation. Will reference it when I eventually habe to re-open it again.

Cheers,
Marianne