Skip to content

Instantly share code, notes, and snippets.

@sammachin
Created March 14, 2017 20:59
Show Gist options
  • Save sammachin/25512bfeaf355e81c572d9599f7d8100 to your computer and use it in GitHub Desktop.
Save sammachin/25512bfeaf355e81c572d9599f7d8100 to your computer and use it in GitHub Desktop.
WTF JSON?
ptt_btn.onmousedown = function(e){
ptt=true;
document.getElementById("tx").innerHTML=status_tx;
if(ws.readyState == ws.OPEN) {
var evt = '{"event": "ptt_on"}';
ws.send(JSON.stringify(evt));
}
}
DEBUG "{\"event\": \"ptt_on\"}"
DEBUG {"event": "ptt_on"}
ERROR Uncaught exception in /socket
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/tornado/websocket.py", line 322, in wrapper
return callback(*args, **kwargs)
File "./server.py", line 140, in on_message
if data["event"] == "connect":
TypeError: string indices must be integers
INFO client disconnected
def on_message(self, message):
# Check if message is Binary or Text
if type(message) == str:
#Processing of Binary Messages
else:
debug(message)
data = json.loads(message)
debug(data)
if data["event"] == "connect":
self.id = data['id']
conns[self.id] = self
elif data["event"] == "ptt_off":
self.frame_buffer.process(self.id)
else:
info("Unknown event: {}".format(data))
self.write_message('ok')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment