Skip to content

Instantly share code, notes, and snippets.

@TurBoss
Forked from forslund/wstest.py
Created September 29, 2018 01:27
Show Gist options
  • Save TurBoss/40c79b29692e6108c8ebed5889577d8d to your computer and use it in GitHub Desktop.
Save TurBoss/40c79b29692e6108c8ebed5889577d8d to your computer and use it in GitHub Desktop.
Connecting to the mycroft message bus.
#! /usr/bin/env python
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