Mercurial > code > home > repos > homeauto
changeset 1005:48a5ce00a881
old updates to barcode player
Ignore-this: d547867bff8b659bd81f58f08ce4a6f9
darcs-hash:20151004111712-312f9-c0b3191d292205c5d7667dfd0161df87d6e59df1
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Sun, 04 Oct 2015 04:17:12 -0700 |
parents | a92fde1612a3 |
children | 63e8a6cd2d3b |
files | service/starArduino/barcodePlayer.py service/starArduino/starArduino.py |
diffstat | 2 files changed, 24 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/service/starArduino/barcodePlayer.py Sun Oct 04 04:16:37 2015 -0700 +++ b/service/starArduino/barcodePlayer.py Sun Oct 04 04:17:12 2015 -0700 @@ -6,11 +6,13 @@ from __future__ import division import cyclone.web, cyclone.httpclient, sys, json, urllib -from twisted.python import log +from twisted.python import log as twlog from twisted.internet import reactor from twisted.internet.defer import inlineCallbacks sys.path.append("/my/proj/homeauto/lib") from cycloneerr import PrettyErrorHandler +from logsetup import log + from pymongo import Connection mpdPaths = Connection("bang", 27017)['barcodePlayer']['mpdPaths'] @@ -36,7 +38,7 @@ post = "http://star:9009/addAndPlay/%s" % urllib.quote(song, safe='') result = (yield cyclone.httpclient.fetch( method="POST", url=post)).body - print result + log.info("post result: %r", result) self.write(result) @@ -45,6 +47,6 @@ (r'/', Index), (r'/barcodeScan', BarcodeScan), ], ) - log.startLogging(sys.stdout) + twlog.startLogging(sys.stdout) reactor.listenTCP(9011, app) reactor.run()
--- a/service/starArduino/starArduino.py Sun Oct 04 04:16:37 2015 -0700 +++ b/service/starArduino/starArduino.py Sun Oct 04 04:17:12 2015 -0700 @@ -6,7 +6,9 @@ import sys,json from twisted.internet import reactor, task -import cyclone.web, restkit +from rdflib import Namespace +import cyclone.web +from cyclone.httpclient import fetch sys.path.append("/my/proj/pixel/shiftweb") from drvarduino import ShiftbriteArduino @@ -18,6 +20,8 @@ sys.path.append("/my/proj/ariremote") from oscserver import ArduinoWatcher +ROOM = Namespace("http://projects.bigasterisk.com/room/") + class Index(PrettyErrorHandler, cyclone.web.RequestHandler): def get(self): @@ -74,7 +78,7 @@ if not code: continue if not code.endswith('\x03'): - print "couldn't read %r" % code + log.warn("couldn't read %r", code) return codeType = {'A':'UPC-A', 'B':'JAN-8', @@ -85,14 +89,18 @@ 'K':'CODE128', }[code[0]] code = code[1:-1] - try: - postBarcode.post(payload=json.dumps( - {'barcodeType':codeType, 'code':code}), - headers={"content-type" : - "application/json"}) - except Exception, e: - print "post err", e - + body = "%s %s %s ." % ( + ROOM['barcodeScan'].n3(), + ROOM['read'].n3(), + ROOM['barcode/%s/%s' % (codeType, code)].n3()) + body = body.encode('utf8') + print "body: %r" % body + fetch("http://bang:9071/oneShot", + method='POST', + timeout=1, + postdata=body, + headers={"content-type" : ["text/n3"]}, + ).addErrback(log.error) class Graph(PrettyErrorHandler, cyclone.web.RequestHandler): def get(self): @@ -121,7 +129,7 @@ aw = ArduinoWatcher(sb) task.LoopingCall(aw.poll).start(1.0/20) - postBarcode = restkit.Resource('http://star:9011/barcodeScan') + postBarcode = 'http://star:9011/barcodeScan' task.LoopingCall(barcodeWatch, sb, postBarcode).start(interval=.5) reactor.listenTCP(9014, cyclone.web.Application([