[SOLVED] Javascript Websocket Conversion

Currently trying to implement a websocket connection into a binding (have done a couple of others and work fine) but I’m struggling with this one and sure I’m missing something silly. Bear with me as my programming skills are mostly ‘googled’ :roll_eyes:

I have the websocket connection up. The problem comes with the data I’m sending.
On send(callbackwrite) I get a 400 bad request message, interpreted as the JSON I’m sending to the server is wrong.

Basing off these libraries for the websocket as the only one out there for Java is polling only (which I have working).

It’s the payload I’m struggling with.
I have successfully logged into the api, and obtained the access token and api key for the login payload on the websocket. Sequence and time stamp I believe I have right. So I don’t know what I’m missing.

Maybe a header? I was reading through the javascript ws-as-promised docs and see there is a ‘pack message’ function. maybe something here I’m missing in jetty.

Any help would be greatly appreciated as other than that the binding is pretty much complete.

2021-01-10 13:25:35.138 [INFO ] [.internal.WebSocket.SonoffConnection] - Sonoff - Authenticate Websocket Message: {"action":"userOnline","userAgent":"app","version":"6","nonce":"BGlwY8tb","apkVersion":"1.8","os":"android","at":"13b69da7a7ed113cbdd4824aeed51914bdd9de04","apiKey":"4b566e1f-532f-4dc0-8321-5807264cc395","ts":1610285135137,"model":"","romVersion":"","sequence":2857306492081639}
2021-01-10 13:25:35.169 [INFO ] [.internal.WebSocket.SonoffConnection] - Sonoff - Websocket Message received: {"error":400,"reason":"Bad Request"}

JSON:

JsonObject json = new JsonObject();
    json.addProperty("action", "userOnline");
    json.addProperty("userAgent", "app");
    json.addProperty("version", "6");
    json.addProperty("nonce", Util.getNonce());
    json.addProperty("apkVersion", "1.8");
    json.addProperty("os", "android");
    json.addProperty("at", accessToken);
    json.addProperty("apiKey", apiKey);
    json.addProperty("ts", ts);
    json.addProperty("model", "");
    json.addProperty("romVersion", "");
    json.addProperty("sequence", sequence);
    String newjson = json.toString();
    logger.info("Sonoff - Authenticate Websocket Message: {}", newjson);
    sendText(newjson);

:roll_eyes: was a simple error, apikey not apiKey.

When you stare at it for that long these little things you just glance over continuously… :laughing: