eclipse-archived / smarthome

Eclipse SmartHome™ project
https://www.eclipse.org/smarthome/
Eclipse Public License 2.0
861 stars 784 forks source link

Tradfri binding does not reestablish connection to gateway after connection loss #6065

Open roben opened 6 years ago

roben commented 6 years ago

Short version: If the gateway gets physically dis- and reconnected the binding does not automatically reconnect to it. To reestablish the connection manually, the IP can be changed to something else and back to the correct value again.

Long version with screenshots and logs: https://community.openhab.org/t/tradfri-binding-loses-connection-after-power-failure-gateway-reboot/47833

Tobster77 commented 5 years ago

@boaks Thanks. I am currently on milestone versions, so I have to wait until this is published. Is there an estimate when this is part of milestone?

boaks commented 5 years ago

Is there an estimate when this is part of milestone?

Yes, as soon, as someone verified, that it improves the behavior for smarthome (https://github.com/eclipse/californium/pull/845#issuecomment-452746663).

1.0.6 is 1.5 years old, the main development (most new features and bugfixes) has also moved for about 2 year to the 2.0.x. Currently only smarthome uses the 1.0.x, so only this project collects experience and reports bugs for that branch.

I am currently on milestone versions,

May be someone else can test the 1.0.7-SNAPSHOT

I tried last year to build smarthome and use it with my tradfri on a raspberry pi. But I failed (I guess, one afternoon is not enough and a "old" i5-8GB box too slow to build it). Is there something like a "shortcut for smarthome with tradfri? (The box to build it is now much faster, R7-32GB)

hreichert commented 5 years ago

@boaks Thanks for your investigations! Same problem here. Currently I'm building ESH with californium 1.0-7-SNAPSHOT and will report back if that solves the connection issue.

Update I can't find where to get the peer InetAddress for the DTLSConnector.forceResumeSessionFor. Any hints?

hreichert commented 5 years ago

@boaks To answer your question: You can try 1) https://www.eclipse.org/smarthome/documentation/development/ide.html 2) Put the californium 1.0.7-SNAPSHOT jars in the "targetplatform" project in the "third-party" folder 3) Edit the "SmartHome-Runtime" launch configuration: under Plug-Ins, activate tradfri, and the californium 1.0.7 jars (and maybe other plugins, use "Validate Plug-ins" button to check) 4) Start the runtime

boaks commented 5 years ago

Update I can't find where to get the peer InetAddress for the DTLSConnector.forceResumeSessionFor. Any hints?

That's the inet-socket-address of the tradfri-gateway. I'm not sure, where this is resolved in SmartHome or where the configuration for that could be accessed. If you have access to the failed Request, you may use Request.getDestinationContext().getPeerAddress().

Tobster77 commented 5 years ago

@boaks Just to get it right: I have to compile the code? So there is nothing I can simply download and test?

boaks commented 5 years ago

https://github.com/eclipse/californium#current-builds

Add the eclipse repo additional should work ... (at least it works "on my machine"). It supports also 1.0.7-SNAPSHOT.

hreichert commented 5 years ago

So, I've made a simple and maybe stupid change to the ESH Tradfri binding to test if DTLSConnector.forceResumeSessionFor makes any difference: image

For me, it works. After a gateway reboot (power cycling) the Bridge and all Things go offline, but they come back in a minute or so (because the Thing Discovery triggers new requests every minute).

@Tobster77 Here you can find a prebuilt version of the changed Tradfri binding and the californium changes from @boaks https://cloud.h0lger.de/index.php/s/lyKNjOhEKarsGak Download all files; Remove Tradfri binding; Drop all files in your "addons" folder; Restart. I recommend to do this on a testing environment. I'm not responsible if my files kill your cat.

boaks commented 5 years ago

For me, it works.

Cool, I will start with the californium 1.0.7 release process on monday :-). (Create an new issue, ask other committers ... I hope, the release could be done until the 18.01.2019)

hreichert commented 5 years ago

@boaks Havent seen this before:

2019-01-12 20:54:45.483 [ERROR] [alifornium.core.network.CoapEndpoint] - Exception in protocol stage thread: java.nio.CharBuffer.flip()Ljava/nio/CharBuffer;
java.lang.NoSuchMethodError: java.nio.CharBuffer.flip()Ljava/nio/CharBuffer;
        at org.eclipse.californium.core.coap.Message.getPayloadTracingString(Message.java:376) ~[246:californium-osgi:1.0.7.SNAPSHOT]
        at org.eclipse.californium.core.coap.Response.toString(Response.java:88) ~[246:californium-osgi:1.0.7.SNAPSHOT]
        at java.lang.String.valueOf(String.java:2994) ~[?:?]
        at java.lang.StringBuilder.append(StringBuilder.java:131) ~[?:?]
        at org.eclipse.californium.core.CoapClient$ObserveMessageObserverImpl.deliver(CoapClient.java:1070) ~[246:californium-osgi:1.0.7.SNAPSHOT]
        at org.eclipse.californium.core.CoapClient$MessageObserverImpl.succeeded(CoapClient.java:996) ~[246:californium-osgi:1.0.7.SNAPSHOT]
        at org.eclipse.californium.core.CoapClient$MessageObserverImpl.onResponse(CoapClient.java:975) ~[246:californium-osgi:1.0.7.SNAPSHOT]
        at org.eclipse.californium.core.coap.Request.setResponse(Request.java:509) ~[246:californium-osgi:1.0.7.SNAPSHOT]
boaks commented 5 years ago

Hm, java 10 or 11?

boaks commented 5 years ago

java.nio.CharBuffer.flip()Ljava/nio/CharBuffer;

There are some trouble with these covariants. That issue is fixed in branch 2.0.x and I can pick the fix to 1.0.x. But the "big thing" behind is, I don't have too much experience in running californium with newer java then 1.8 :-).

boaks commented 5 years ago

I pushed the covariant fix and build the 1.0.7-SNAPSHOT. Remove your 1.0.7-SNAPSHOT and load it again from eclipse repo.

boaks commented 5 years ago

Cool, I will start with the californium 1.0.7 release process on monday :-).

After the "next issue" above, I would prefer to have it tested some more. So wait a couple of days, what show up next?

boaks commented 5 years ago

@hreichert

Did you use java 9 or newer? Could you retest the latest fix for the covariants? Does it work now?

hreichert commented 5 years ago

@boaks It was Java8. I will try it with your new californium snapshot.

kvoit commented 5 years ago

My Tradfri is connected via VPN and I run into the same issue. Let me add that I do not need to change the IP. For me it is enough to open the Thing config of the gateway in PaperUI and hit the tick sympol to get the binding online again.

boaks commented 5 years ago

It was Java8

The good part of that is, I run it also mainly with that, so it should work quite well. The other part is, then I don't know, why java.lang.NoSuchMethodError: java.nio.CharBuffer.flip()Ljava/nio/CharBuffer is reported :-). May be java9 (or newer) was used to build it.

I will try it with your new californium snapshot.

Thanks!

boaks commented 5 years ago

My Tradfri is connected via VPN and I run into the same issue.

The same as this github issue? Or with the fix and update into java.lang.NoSuchMethodError: java.nio.CharBuffer.flip()Ljava/nio/CharBuffer;?

boaks commented 5 years ago

Let me add that I do not need to change the IP. For me it is enough to open the Thing config of the gateway in PaperUI and hit the tick sympol to get the binding online again.

That fits to my analysis https://github.com/eclipse/smarthome/issues/6065#issuecomment-453725928 May be you can also check the fix.

kvoit commented 5 years ago

My Tradfri is connected via VPN and I run into the same issue.

The same as this github issue?

Yes, same as this issue. At least when the connection is down for a while, Tradfri will no go online again and I have to open and save the Thing config of the gateway (without altering anything) to get it back working.

I will try to find time for testing the fix. Thanks!

boaks commented 5 years ago

@hreichert

I retested to compile with openjdk-11 and execute with openjdk-8 and got the java.lang.NoSuchMethodError: java.nio.CharBuffer.flip()Ljava/nio/CharBuffer . The java 11 compiler reports also "warning: [options] bootstrap class path not set in conjunction with -source 8 1 warning"

Now I'm not sure, did you build it it on your own? Or did you download it from the eclipse maven repo? In the download case, I guess, I need to adjust the build on the eclipse jenkins to prevent other errors.

hreichert commented 5 years ago

@boaks Ah well you're right, I've built it myself with Java 11 and let it run on Java 8 on a different machine. I tested again with 1.0.7-20190119.070624-584 from the eclipse maven repository, and for me it's working well!

boaks commented 5 years ago

Great! If no other issue is raised at this weekend, I start the "release process" on Monday.

boaks commented 5 years ago

Californium released the 1.0.7 today including the fix for empty session ids mentioned above. Please retest and maybe close this issue. I'm looking forward to the next issues :-).

hreichert commented 5 years ago

Thank you @boaks FTR: There are additional changes needed in the Tradfri binding. PR following.

kaikreuzer commented 5 years ago

Thanks! @hreichert Please create the PR against https://github.com/openhab/openhab2-addons/tree/master/addons/binding/org.openhab.binding.tradfri (see here for the reasons).

cweitkamp commented 5 years ago

A PR for the new californium release has been created and merged in https://github.com/openhab/openhab-core/pull/475. Currently we will skip ESH.

@boaks Thank you very much for your work.

Tobster77 commented 5 years ago

@boaks, @hreichert, @cweitkamp Thanks a lot for caring :-)

Tobster77 commented 4 years ago

A PR for the new californium release has been created and merged in openhab/openhab-core#475. Currently we will skip ESH.

@boaks Thank you very much for your work.

This did not improve the decribed issue. Is there any recommendation?

5iver commented 4 years ago

@Tobster77, seeing as this repo is dead (see #6883) and development has moved to openHAB, it would be best to create a new issue for the Tradfri binding. Of course, that is assuming you are using OH!

boaks commented 4 years ago

@Tobster77

This and many other issues around tradfri and californium seems to be a mix of several different things. And the fix in californium only addresses to reconnect without restart.

If you create a new issue in openHab, maybe you can add the issue number here as well. Then a can follow up your issue.

In the meantime openHab uses Californium 2.0 and at least I got some info, that this improved the stability.

Tobster77 commented 4 years ago

Meanwhile this is discussed also here:https://community.openhab.org/t/tradfri-binding-loses-connection-after-power-failure-gateway-reboot/47833Am 12.03.2020 14:06 schrieb Achim Kraus notifications@github.com: @Tobster77 This and many other issues around tradfri and californium seems to be a mix of several different things. And the fix in californium only addresses to reconnect without restart. If you create a new issue in openHab, maybe you can add the issue number here as well. Then a can follow up your issue. In the meantime openHab uses Californium 2.0 and at least I got some info, that this improved the stability.

—You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub, or unsubscribe.