Created
August 15, 2017 10:02
-
-
Save forslund/064384b0d5d073a2a37cc092462e609c to your computer and use it in GitHub Desktop.
Connecting to the mycroft message bus.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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
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"