Remote management websocket issue


I want to use the remote management API to trigger sampling requests on my ST IOT Kit.
The hello handshake works but then I have no response after sending the sample request, websocket is then closed by server after 30 seconds. My message looks correct, here’s the dump from wireshark:

{"sample": {"label": "noise", "length": 10000, "path": "/api/training/data", "hmacKey": "xxxxxxxxxxxxx", "interval": 0.0625, "sensor": "Built-in microphone"}}

Someone has an idea? If I send this message without hello handshake, the server asks to authenticate first so I suppose my request is received correctly.


Hi @aureleq, what flow are you using? Are you trying to trigger a sample request to the ST IoT Discovery Kit by calling into the remote management server directly? Or are you running an alternative client on the discovery kit?

Hi @janjongboom,

I am trying to trigger a sample request to the kit by calling the remote management server.
I’m just realizing it might not be the correct flow as only the Studio can send Sample Requests?

Yeah, the remote management API is for the dev kit to communicate with. To start sampling you should go through studio. But… the start sampling function is only available through the socket API right now which is not easily accessible nor documented yet.

Anyway, here is one way you can do it. Just be aware that the socket token expires every week or so, so not really a proper way forward.

  1. Get a socket token. You can get it from the JavaScript console on any studio page:


  2. Connect to the websocket API:

var socketToken = '...';
var socket = new WebSocket('wss://' + encodeURIComponent(socketToken) + '&EIO=3&transport=websocket');
socket.onopen = () => { console.log('socket is open', socket.readyState); }
socket.onerror = err => console.error('socket error', err);
socket.onmessage = msg => console.log('socket message', msg);
  1. Send a start sampling request:
socket.send('422["start-sampling",{"deviceId":"C4:7F:51:94:4C:85","label":"idle","length":5000,"path":"/api/training/data","interval":16,"sensor":"Built-in accelerometer"}]')


I’ve added items to our backlog to document the websocket interface, and to create socket tokens from the API.

That’s perfect! I was going to rollback to an AT commands script but I much prefer this remote solution :slight_smile:
I’ll put my code and project on github once it’s all done.

1 Like

@aureleq We rolling out two new proper APIs now for this:

Will be deployed by tomorrow. At some point we’ll also document the web socket API, but you can figure it out pretty quickly if you just look at the messages coming in over the web socket.

1 Like

Thanks @janjongboom!

I managed with the previous workaround but this solution will be more clean :slight_smile:


@aureleq, yeah, the websocket way of starting will be retired; so better use the proper API. That will be stable :slight_smile: