Robot Not a Dev? Buy Now
Not a Dev?

Misty Community Forum

Listening for Event Messages with Simple WebSocket Client

We thought it would helpful to post about a third-party tool we use here at Misty HQ to stream data from different event types via Misty’s WebSocket server.

Simple WebSocket Client is a Chrome extension you can download from the Chrome Web Store. You can use this tool to establish a connection to Misty’s WebSocket server. Then, pass in a JSON payload to subscribe to messages from a specific even type.

Here’s an example of how you can use this tool to stream data from Misty’s HazardNotification event type:

  1. Download Simple WebSocket Client from the Chrome Web Store
  2. Boot up your robot.
  3. When Misty’s eyes are fully open, open the Simple WebSocket Client. In the URL: field under Server Location, enter ws://<robot-ip-address>/pubsub. Click Open to open a connection to your robot’s WebSocket server. Tip: You’ll know the connection is successful when the Status field shows Opened.
  4. To create listener for HazardNotifications events, copy the following JSON payload into the Requests field and click Send. This example uses Hazards as the EventName, but you can customize this value as you like.
       "$id": "1",
       "Operation": "subscribe",
       "Type": "HazardNotification",
       "DebounceMs": 100,
       "EventName": "Hazards",
  1. When the subscription is established, you should see the following message from Misty in the Message Log field:
{"eventName":"Hazards","message":"Registration Status: API event registered."}
  1. Now that you’ve subscribed to HazardNotification events, you should see messages in the Message Log any time Misty’s hazard system is triggered. Try pressing her bump sensors or moving your hand in front of a time-of-flight sensor to try it out. When you trigger a hazard state, you should see a message that resembles the example below. Tip: You can determine which hazard states are triggered in the responses by using Ctrl + F and searching the page for true statuses. Read more about HazardNotification events in the developer docs.
{"eventName":"Hazards","message":{"bumpSensorsHazardState":[{"inHazard":false,"sensorName":"Bump_FrontRight"},{"inHazard":false,"sensorName":"Bump_FrontLeft"},{"inHazard":false,"sensorName":"Bump_RearRight"},{"inHazard":false,"sensorName":"Bump_RearLeft"}],"created":"2019-10-04T21:02:46.9964641Z","criticalInternalError":0,"currentSensorsHazard":[{"inHazard":false,"sensorName":"CurrentSensor_RightTrack"},{"inHazard":false,"sensorName":"CurrentSensor_LeftTrack"},{"inHazard":false,"sensorName":"CurrentSensor_RightArm"},{"inHazard":false,"sensorName":"CurrentSensor_LeftArm"},{"inHazard":false,"sensorName":"CurrentSensor_HeadPitch"},{"inHazard":false,"sensorName":"CurrentSensor_HeadRoll"},{"inHazard":false,"sensorName":"CurrentSensor_HeadYaw"}],"driveStopped":[{"inHazard":false,"sensorName":"Front right hazard"},{"inHazard":false,"sensorName":"Front center hazard"},{"inHazard":false,"sensorName":"Front left hazard"},{"inHazard":false,"sensorName":"Back right hazard"},{"inHazard":false,"sensorName":"Back center hazard"},{"inHazard":false,"sensorName":"Back left hazard"}],"excessiveSpeedHazard":[{"inHazard":false,"sensorName":"RightDrive"},{"inHazard":false,"sensorName":"LeftDrive"},{"inHazard":false,"sensorName":"RightArm"},{"inHazard":false,"sensorName":"LeftArm"},{"inHazard":false,"sensorName":"HeadPitch"},{"inHazard":false,"sensorName":"HeadRoll"},{"inHazard":false,"sensorName":"HeadYaw"}],"motorStallHazard":[{"inHazard":false,"sensorName":"RightDrive"},{"inHazard":false,"sensorName":"LeftDrive"},{"inHazard":false,"sensorName":"RightArm"},{"inHazard":false,"sensorName":"LeftArm"},{"inHazard":false,"sensorName":"HeadPitch"},{"inHazard":false,"sensorName":"HeadRoll"},{"inHazard":false,"sensorName":"HeadYaw"}],"timeOfFlightSensorsHazardState":[{"inHazard":false,"sensorName":"TOF_Right"},{"inHazard":false,"sensorName":"TOF_Center"},{"inHazard":false,"sensorName":"TOF_Left"},{"inHazard":false,"sensorName":"TOF_Back"},{"inHazard":false,"sensorName":"TOF_DownFrontRight"},{"inHazard":true,"sensorName":"TOF_DownFrontLeft"},{"inHazard":false,"sensorName":"TOF_DownBackRight"},{"inHazard":false,"sensorName":"TOF_DownBackLeft"}]}}

You can use the Simple WebSocket Client to set up a subscription for any of Misty’s event types. You can also add EventConditions and ReturnProperty key/value pairs to apply filters on the data that Misty sends back when a specific event is triggered (see the docs for an example of how to use these fields in your subscription).

Have fun, and let us know if you have questions or feedback! :robot:

@jerry This is what we talked about, thought you might like a reference to it!

Also @milsonian I thought you might appreciate this as well :tada: