Skip to content

Instantly share code, notes, and snippets.

@forslund
Created August 15, 2017 10:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save forslund/064384b0d5d073a2a37cc092462e609c to your computer and use it in GitHub Desktop.
Save forslund/064384b0d5d073a2a37cc092462e609c 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()
@jshep321
Copy link

jshep321 commented Dec 2, 2019

I couldn't get this to work likely due to bash+python quote escaping issues, so I rewrote it, also made the IP and message type static in my "sendutt.py" program.

See here: https://gist.github.com/jshep321/3b13f105ffb8b9eace9fa57f03fed6d7.js"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment