Skip to content

Instantly share code, notes, and snippets.

@jrwarwick
Forked from forslund/wstest.py
Last active May 24, 2018 23:22
Show Gist options
  • Save jrwarwick/8df47f2f69bdd94bbb92b227f43e9ca8 to your computer and use it in GitHub Desktop.
Save jrwarwick/8df47f2f69bdd94bbb92b227f43e9ca8 to your computer and use it in GitHub Desktop.
Connecting to the mycroft message bus.
#! /usr/bin/env python
#pip install websocket-client
#python mycroft_ws_test.py localhost recognizer_loop:utterance '{"utterances": ["what time is it"]}'
import sys
from websocket import create_connection
uri = 'ws://' + sys.argv[1] + ':8181/core'
ws = create_connection(uri)
print("Sending " + sys.argv[2] + " to " + uri + "...")
if len(sys.argv) >= 4:
data = sys.argv[3]
else:
data = "{}"
message = '{"type": "' + sys.argv[2] + '", "data": ' + data +'}'
result = ws.send(message)
print("Receiving...")
result = ws.recv()
print("Received '%s'" % result)
ws.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment