Last active
December 29, 2015 14:38
-
-
Save scottgwald/7685005 to your computer and use it in GitHub Desktop.
Send data from Glass to a python server. Uses the Go server as an intermediary. #wearscript
This file contains hidden or 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
<html style="width:100%; height:100%; overflow:hidden"> | |
<body style="width:100%; height:100%; overflow:hidden; margin:0"> | |
<canvas id="canvas" width="640" height="360" style="display:block"></canvas> | |
<script> | |
function server() { | |
WS.say('About to send some data.'); | |
WS.blobSend('glassdata', 'Some nonsense 234234'); | |
} | |
function main() { | |
if (WS.scriptVersion(0)) return; | |
WS.serverConnect('{{WSUrl}}', 'server'); | |
} | |
window.onload = main; | |
</script></body></html> |
This file contains hidden or 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 gevent.monkey | |
gevent.monkey.patch_all() | |
import gevent | |
import websocket | |
import argparse | |
import msgpack | |
import json | |
import irc.bot | |
import irc.strings | |
class MinimalListenerServer(): | |
def __init__(self, endpoint): | |
self.ws = websocket.create_connection(endpoint) | |
def start(self): | |
while True: | |
print('Listening') | |
msg = msgpack.loads(self.ws.recv()) | |
print(msg) | |
if msg[0] == 'blob' and msg[1] == 'glassdata': | |
print("I FOUND MY MSG") | |
def main(): | |
parser = argparse.ArgumentParser(description='WearScript Glassdata: Get data from Glass') | |
parser.add_argument('endpoint') | |
listenerServer = MinimalListenerServer(**vars(parser.parse_args())) | |
listenerServer.start() | |
if __name__ == "__main__": | |
main() |
This file contains hidden or 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
./glassdata.py ws://{{yourGoServer}}/ws/web/{{copySecretFromPlayground}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment