Erste Schritte Help with websocket protocol implementation

Diskutiere Help with websocket protocol implementation im Java Basics - Anfänger-Themen Bereich.
L

lomi

Hello all,

I try to creat a very simple websocket application for a esp32 sensor.

The protocol of the sensor is very easy
1. Connect to ws://IP:654 via websocket client
2. Returned value is "{"type":"Auth"}"
3. Send {"type":"auth", "command":"logmein"}
4. Returned value is "{"type":"Authok"}"
5. Than send a request like "{"type":"sensor", "value":"get"}"
3.returned value is "{"type":"sensor", "value":"55"}"

But I failed already with the first connection
Here is my code

Java:
try {
            URI uri;
            uri = new URI("ws://" + ip + ":845");

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

            try {
                Session=webSocketClient
                        .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);
        }
Used library is
org.eclipse.jetty.websocket.api.Session

Error is
Web socket connect failed " + uri.toString(), e);
Can someone help me please??
 
J

JustNobody

Please give exact error message including the Exception with stacktrace and not just the line where the error occurred.
 
J

JustNobody

And in the text you give the port 654 but in your code you have port 845.
 
L

lomi

Hello,
it's a null pointer exception

Code:
Web socket connect failed java.lang.NullPointerException
java.lang.NullPointerException: null

at org.openhab.binding.yioremote.internal.YIOremoteHandler.initialize(YIOremoteHandler.java:102)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:152)
    at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:52)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
 
Thema: 

Help with websocket protocol implementation

Passende Stellenanzeigen aus deiner Region:
Anzeige

Neue Themen

Anzeige

Anzeige
Oben