Remote-management wss closes automatically after some time , after data is uploaded to studio

I’m trying to build a web browser based android mobile client (mentioned here).

For the training, the data upload section the pseudo code is here:

when in training mode:
    Make the device available on Edge-Impulse Studio by websocket handshake
    if sampling request received from Edge-Impulse studio over websockets:
       sample data for required length

    when sampling finished:
        [1] notify the studio through the designated websocket message 
        [2] in the data structure (with other details) push the returned data array
        [3] encode the data structure (SHA-256 and hmacKey using https://github.com/Caligatio/jsSHA on the browser side as crypto lib is for nodejs)
        [4] Upload the data using fetch() 

I have another issue now :sweat:
After the data uploads successfully, the wss connection closes after few seconds upon upload.
A wss closure request is received and the closure code is 1005, meaning it expected a close status but received none. :pleading_face:
I don’t know, if there should be a ping-pong messaging to keep the wss connection open, until I request a closure from my client.

Any help or is it my code ()

Hi @dattasaurabh82, you should indeed ping every few seconds, see e.g. https://github.com/edgeimpulse/mobile-client/blob/989daed26d8889013ec19e37adc1eba79b703468/client/remote-mgmt.ts#L56

1 Like

Trying it out now. Thanks for the super prompt reply…
Will report back soon…

It’s working now …

Here’s the over-simplified pseudo-code:

switch button to open connection:
   wss connection established
   
   on connection established:
        [1] send handshake hello routine 
        [2] set send_pings var is true
        [2] if send_pings var is true:
                  at set interval : send pings
            else:
                  stop the pinging by clearing the interval


   on message:
       [1] if returned event data has pong, return null or else our console won't be happy :sweat_smile:
       [2]...[x] also handle returned response from hello routine and other messages.
 

switch button to close connection:
    set send_pings var is false
    clean close the wss connection
1 Like