Help needed for some basic websocket binding

Hello,
I want to implement a new binding for the yio remote (see yio-remote.com)

therefore I started today with the implementing of a simple websocket code

The protocol is stated here:

try {
            URI uri;
            uri = new URI("ws://" + config.yiodockhostip + ":946");

            try {
                YIOremoteBindingConstants.yiodockwebSocketClient.start();
            } catch (Exception e) {
                logger.warn("Web socket start failed", e);
                // throw new IOException("Web socket start failed");
            }

            try {
                YIOremoteBindingConstants.yiodockwebSocketClientSession = YIOremoteBindingConstants.yiodockwebSocketClient
                        .connect(this, uri, new ClientUpgradeRequest()).get();
            } catch (Exception e) {
                logger.warn("Web socket connect failed " + uri.toString(), e);
                // throw new IOException("Web socket start failed");
            }

        } catch (URISyntaxException e) {
            logger.debug("Initialize web socket failed", e);
        }
        if (YIOremoteBindingConstants.yiodockwebSocketClientSession != null) {
            updateStatus(ThingStatus.ONLINE);
        } else {
            updateStatus(ThingStatus.OFFLINE);
        }

but it always can’t connect even I checked the URI is correct any suggestion what I am doing wrong?

Difficult to say as this is only a small part of the code. However it looks like your using a websocket client field that is a static field in your constants class, and assign to another static field in that class. That might not be a cause to the specific issue here, but if I’m correct, its certainly an anti-pattern. Look at other bindings how they create a websocket connection. For example look at the deconz binding.

And when asking for help debugging a problem with a library, it’s always a good idea to provide a link to the library code.

Otherwise people have to guess at what it does instead of knowing what it does.

1 Like

see

These are not constants and don’t belong in a constants file.

YIOremoteBindingConstants.java

// List of all used global variables
    public static final WebSocketClient yiodockwebSocketClient = new WebSocketClient();
    public static @Nullable Session yiodockwebSocketClientSession = null;

This help me Thanks

Wouldent you just get the remote to control openhab using the rest api

Sample config.json Integration entry :

 "openhab":
    {
        "log": "debug",
        "data":
        [
            {
                "url": "http://192.168.1.100:8080/rest",
                "polling_interval": 2000,
                "friendly_name": "RIC's OpenHab",
                "id": "openhab"
            }
        ]
    },

Because the dock can send/receive IR commands for other rules…