Failed to execute the root REST API error trying to configure Remote openHAB Binding [Solved]

As suggested by @Lolodomo on Is there a way to safely use the Remote Binding over the Internet? - #11 by Lolodomo, I tried to set up the Remote openHAB Binding using myopenhab.org.

I am running openHAB 3.1.0-1 Release version on two different Pi 4Bsusing OpenHABian at two different locations I’m trying to access the remote installation through its myopenhab.org account.
.
I added the binding using the UI and entered these configuration parameters:

I tried both /rest and /rest/ with the same result.

This is what I see in the log. I tried increasing the log level to DEBUG for the binding, but that didn’t generate anymore information.

2021-09-09 13:30:20.391 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from UNINITIALIZED (DISABLED) to INITIALIZING
2021-09-09 13:30:20.406 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from INITIALIZING to UNKNOWN
2021-09-09 13:30:35.441 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from UNKNOWN to OFFLINE (COMMUNICATION_ERROR): Failed to execute the root REST API: java.util.concurrent.ExecutionException: java.net.SocketTimeoutException: Connect Timeout

I searched the Community, but didn’t find anything that looked like it would help.

Rather than hijacking my own thread on which others who know a lot more than I do are exchanging lost of information related to the original question, I started this thread. Once I get this resolved I will add a link on that thread to this solution.

Any suggestions of what to try next?

Thanks

Is there some reason you are expecting this OH instance to be able to communicate with the remote one? i.e. have you set up the VLAN or whatever you are using to bridge the sites

Based on Is there a way to safely use the Remote Binding over the Internet? - #10 by Lolodomo and the comment that follows it in the thread, I thought it would work with out having to set anything else. Perhaps I missed something.

You have of course to setup your username/password, the ones for your cloud account (linked to your remote server).

And keep the default REST path.

And yes, no need for VPN.

Thanks for the help. It likes like the problem is that it doesn’t have the myopenhab.org credentials. I can’t figure out where to provide them.

I don’t see in the UI for the Bridge Thing where to enter the user id and password for the cloud server (myopenHAB.org). There are entries for a user ID and password for the openHAB server, but it says that is if you aren’t using an API token, but I am using a token. I tried putting the myopenhab credentials there, but that didn’t work.

Seems like I’m missing something very simple.

Yes you have to enter them in your thing configuration, the two last settings in your screen capture.

If your remote server is OH3, you can additionally use an application token, it must be the token setup for your remote server, not your local server.

I will try again this evening to show to you a working bridge thing setup.

Thanks. I will play with when I can today and will let you know if I figure it out, but otherwise I look forward to you showing me how it works.

This is trivial for a remote OH2 server, just a little more complicated with remote OH3 server due to the application token iuf you want full features.

I guess you are setting a wrong port number. Normally, the cloud instance is accessible on port 443.

Here is an example of working thing setup of course with a valid username/password for your cloud instance.

If you like, you can then add a valid application token to get the additional features.

You prove that it may be not as simple as I magined to setup such connection. So I just added an example in the documentation:

2 Likes

Thanks. Changed the server to 443 and the Bridge Thing is now online! Thanks for your assistance.

I will check it out and let you know if I run into any unexpected issues. But I think this is going to be great, and much easier (for someone like me who knows just enough to eventually make most things work in openHAB) than trying figure out how to set up peers on the two Wireguard installations on the same Pi as openHAB.

The binding created channels for all of the Item states on the remote server as expected, which is great. And the ones I tested seem to work well.

I do see in the log it switching on and offline:

2021-09-10 15:34:35.832 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from OFFLINE (COMMUNICATION_ERROR): Error occurred while receiving events to ONLINE
2021-09-10 15:35:50.350 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): Error occurred while receiving events
2021-09-10 15:37:55.035 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from OFFLINE (COMMUNICATION_ERROR): Error occurred while receiving events to ONLINE
2021-09-10 15:38:55.655 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): Error occurred while receiving events
2021-09-10 15:42:00.239 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from OFFLINE (COMMUNICATION_ERROR): Error occurred while receiving events to ONLINE
2021-09-10 15:43:00.877 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): Error occurred while receiving events
2021-09-10 15:46:05.445 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from OFFLINE (COMMUNICATION_ERROR): Error occurred while receiving events to ONLINE
2021-09-10 15:47:06.110 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): Error occurred while receiving events
2021-09-10 15:50:10.549 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from OFFLINE (COMMUNICATION_ERROR): Error occurred while receiving events to ONLINE
2021-09-10 15:51:47.012 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): Error occurred while receiving events
2021-09-10 15:53:52.913 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from OFFLINE (COMMUNICATION_ERROR): Error occurred while receiving events to ONLINE
2021-09-10 15:55:50.387 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): Error occurred while receiving events
2021-09-10 15:57:19.970 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from OFFLINE (COMMUNICATION_ERROR): Error occurred while receiving events to ONLINE
2021-09-10 16:00:50.368 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): Error occurred while receiving events
2021-09-10 16:02:19.922 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from OFFLINE (COMMUNICATION_ERROR): Error occurred while receiving events to ONLINE
2021-09-10 16:03:20.566 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): Error occurred while receiving events
2021-09-10 16:06:25.105 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from OFFLINE (COMMUNICATION_ERROR): Error occurred while receiving events to ONLINE
2021-09-10 16:07:34.256 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): Error occurred while receiving events
2021-09-10 16:09:40.147 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from OFFLINE (COMMUNICATION_ERROR): Error occurred while receiving events to ONLINE
2021-09-10 16:10:50.328 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): Error occurred while receiving events
2021-09-10 16:12:55.035 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from OFFLINE (COMMUNICATION_ERROR): Error occurred while receiving events to ONLINE

May not be a problem, but I thought I would mention it.

The Pi openHAB runs on is connected via ethernet to the fiber modem, so they should have a good connection.

Enable binding DEBUG logs to see what is this event.

Should have thought of that:

2021-09-10 17:18:22.689 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - Error occurred while receiving events
java.io.IOException: Premature EOF
	at sun.net.www.http.ChunkedInputStream.readAheadBlocking(Unknown Source) ~[?:?]
	at sun.net.www.http.ChunkedInputStream.readAhead(Unknown Source) ~[?:?]
	at sun.net.www.http.ChunkedInputStream.read(Unknown Source) ~[?:?]
	at java.io.FilterInputStream.read(Unknown Source) ~[?:?]
	at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(Unknown Source) ~[?:?]
	at sun.nio.cs.StreamDecoder.readBytes(Unknown Source) ~[?:?]
	at sun.nio.cs.StreamDecoder.implRead(Unknown Source) ~[?:?]
	at sun.nio.cs.StreamDecoder.read(Unknown Source) ~[?:?]
	at java.io.InputStreamReader.read(Unknown Source) ~[?:?]
	at java.io.BufferedReader.fill(Unknown Source) ~[?:?]
	at java.io.BufferedReader.readLine(Unknown Source) ~[?:?]
	at java.io.BufferedReader.readLine(Unknown Source) ~[?:?]
	at org.apache.cxf.jaxrs.sse.client.InboundSseEventProcessor.lambda$process$0(InboundSseEventProcessor.java:115) ~[?:?]
	at java.util.concurrent.FutureTask.run(Unknown Source) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:?]
	at java.lang.Thread.run(Unknown Source) [?:?]
==> /var/log/openhab/events.log <==
2021-09-10 17:18:22.698 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): Error occurred while receiving events

And back online:

2021-09-10 17:20:21.108 [DEBUG] [l.handler.RemoteopenhabBridgeHandler] - Time to check server accessibility
2021-09-10 17:20:21.112 [DEBUG] [l.handler.RemoteopenhabBridgeHandler] - Try the root REST API...
2021-09-10 17:20:21.114 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - Request GET https://myopenhab.org/rest/
2021-09-10 17:20:22.366 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - REST API version = 4
2021-09-10 17:20:22.367 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - REST API items = https://myopenhab.org/rest/items
2021-09-10 17:20:22.368 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - REST API things = https://myopenhab.org/rest/things
2021-09-10 17:20:22.369 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - REST API events = https://myopenhab.org/rest/events
2021-09-10 17:20:22.369 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - topic namespace = openhab
2021-09-10 17:20:22.370 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - Request GET https://myopenhab.org/rest/items?recursive=false&fields=name,type,groupType,state,stateDescription
2021-09-10 17:20:25.586 [DEBUG] [l.handler.RemoteopenhabBridgeHandler] - 533 channels defined (with 0 different channel types) for the thing remoteopenhab:server:ee460b8c80 (from 609 items including 76 groups)
2021-09-10 17:20:25.608 [DEBUG] [l.handler.RemoteopenhabBridgeHandler] - updateState remoteopenhab:server:ee460b8c80:OfficeDimmerMQTTThing_OfficeDimmerPowerOnOff with OFF
2021-09-10 17:20:25.614 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - Closing EventSource
2021-09-10 17:20:25.616 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - Succesfully closed existing EventSource
2021-09-10 17:20:25.617 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - EventSource stopped
2021-09-10 17:20:25.618 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - Opening EventSource
2021-09-10 17:20:25.619 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - Reopening EventSource
2021-09-10 17:20:25.620 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - Opening new EventSource https://myopenhab.org/rest/events?topics=openhab/items/*/*,openhab/things/*/*,openhab/channels/*/triggered,openhab/channels/*/descriptionchanged
2021-09-10 17:20:25.621 [DEBUG] [.RemoteopenhabStreamingRequestFilter] - Set credential token. target=https://myopenhab.org/rest/events?topics=openhab/items/*/*,openhab/things/*/*,openhab/channels/*/triggered,openhab/channels/*/descriptionchanged, token=Z21oeWRlK3NwcmluZ0BnbWFpbC5jb206Q291Z2FyNzkr
==> /var/log/openhab/events.log <==
2021-09-10 17:20:25.618 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'remoteopenhab:server:ee460b8c80' changed from OFFLINE (COMMUNICATION_ERROR): Error occurred while receiving events to ONLINE
202

Apparently the myopenhab WEB site is triggering this SSE error in your case.
I never encountered this case but at the same time I never run such scenario during many minutes. I just restarted such connection and I will see if I can reproduce this error after few minutes.

Is your remote server sending regular updates (mine is updating one date every minute).

Ok, I stopped my new test after 30 minutes of full stability of the SSE connection.

Even if it should not be a problem, in case you have no regular updates in your remote server, you could try adding the NTP binding and link a date item in your remote server, just to be sure to have a minimum and regular activity on your remote server and as a consequence an actiity on the SSE connection opened by the remoteopenhab binding.
I am curious to know if it could make a difference. It should not in theory.

I added the NTP binding yesterday to the remote server and created a Thing and linked an Item to the date time channel. The thing never went on line. I was just starting to troubleshoot and I lost access to the remote server. I wondered if a needed to open the port on the router, but I’m usually leery of that. Regardless, I will be there on Tuesday and will check it out and report. Sorry for the delay.

Everything seems to be working as expected, with none of the Communication switching that I experienced earlier. When I got home, I found that my router was behaving oddly which impacted some but not all smart home devices. I rebooted the router which seems to have solved that. openHAB was behaving strangely (the iCloud binding was “Online” but wasn’t updating and the Network Binding wasn’t responding as devices connected and disconnect to the router. I stopped openHAB (systemctl stop openhab) and cleared the cache (openhab-cli clear-cache) and restarted (systemctl start openhab).(all on a Pi 4B running openHABian). After that, everything, including the Remote openHAB Binding is working as expected.

I went ahead an set it up going the other way (added the Remote openHAB Binding to the remote server), and I can access its Items on the local server.

Thanks for developing this helpful, secure way for two remote openHAB installation to communicate with each other.

If I correctly understand what you finally did, you are in the case where you can easily enter in a loop (B remote server for A and A remote server for B). Don’t remember if the loop is certain or only depending on your setup.