Home Community Blog Buy Now

Misty Community Forum

How to unregister all events?

If I do not unregister an event subscription before closing a WebSocket from offboard (to /pubsub), is there some way to unregister it later?

In general, can I perform a bulk unregister of events? (E.g., get a list of all subscriptions created from past WebSocket connections that were not unregistered, and then unregister each.)

My motivating use-case is that in practice I might drop a WebSocket connection before being able to send a 'Operation': 'subscribe', 'Type': 'SkillData', ... message. Then, after trying to reconnect with the same EventName, the response is

{"eventName":"SkillData","message":"Registration Status: Cannot register an event with same name (SkillData) as a previously registered event."}

Thus far, I have only had success by changing the EventName or rebooting the robot. I am OK to simply generate a new name, but I am concerned that there is some memory leak onboard.

Hi Scott, you can unregister for all events by using the Command Center Unregister option in Advanced Options and not entering in an event name.

Where is the “Unregister” option? I located an “Unsubscribe” button and tried it without entering an event name, but the error remains.

Besides using the Command Center as you describe, I found the actual API command used by tracing the Command Center: for the Unsubscribe action without event name, it sends


over the WebSocket connection. Therefore, I also tried to send this from my own code, but the error remains.

Can you reproduce the error that I described? Alternatively, can someone confirm that there are no bad side effects of randomly generating a different EventName to avoid the error?

@slivingston, I’ve been able to reproduce this using Simple WebSocket Client - Chrome Web Store. Steps:

  1. Open a WebSocket connection
  2. Send a message to subscribe to an event with event name myEvent
  3. Close the WebSocket connection without unsubscribing from myEvent
  4. Open another WebSocket connection
  5. Send an unsubscribe message without specifying an event (in theory this would end all subscriptions)
  6. Send a message to subscribe to an event with event name myEvent. Attempt fails with message "Registration Status: Cannot register an event with same name (myEvent) as a previously registered event."

This may be a bug, or perhaps there’s some undocumented behavior that we need to provide information about.

Per your question:

If there are side effects, I do not believe they’re severe… I believe this is actually how the Misty Robotics Skill Runner web page streams SkillData messages (by prepending the event name with a random sequence of numbers at subscribe time). I’ll see if someone with more knowledge can share it here.

1 Like

As far as I am concerned, this is a sufficient solution. We can mark this as resolved.

Hi @slivingston,

So, what is the solution? I don’t follow the conversation above. My Misty borrows the code from lightSocket from Command Center for her Face Recognition because I can’t use the call from API Explorer to get the person name.

I can’t solve the problem:

“Registration Status: Cannot register an event with same name (myEvent) as a previously registered event.”

Can you provide me a sample code for this solution please?

Many thanks.

Best regards,

My solution is to generate a random suffix for the EventName, as demonstrated in the MistyPackageManager code:

  'Operation': 'subscribe',
  'Type': 'SkillData',
  'DebounceMS': None,
  'EventName': 'SkillData{}'.format(random.randint(0,1000)),
  'Message': '',
  'ReturnProperty': None,

which is Python code (assumes that you previously import json and import random).

Hi @slivingston,

Is there a solution that I can implement on JavaScript? My apps are written in JavaScript. I borrowed LightSocket and FetchClient from the command center to get my tasks done. Many thanks.

Best regards,

Yes. Decent JavaScript runtimes have a random number generator available. Try Math.random, which is described at Math.random() - JavaScript | MDN

Hi @slivingston,

Many thanks.

I changed lightSocket.Subscribe(“FaceRecognition”, “FaceRecognition”…) to lightSocket.Subscribe(randomEventName, “FaceRecognition”…), so as lightSocket.Unsubscribe. It worked very well. Very happy. No trouble now.

Best regards,

1 Like