Mercurial > code > home > repos > homeauto
diff service/arduinoNode/arduinoNode.py @ 170:376599552a4c
polymer board debug page with working output widgets
Ignore-this: 3157d0c47a91afe47b30a5f182629d93
author | drewp@bigasterisk.com |
---|---|
date | Mon, 13 Apr 2015 23:30:12 -0700 |
parents | d228105749ac |
children | f81c4d3d774b |
line wrap: on
line diff
--- a/service/arduinoNode/arduinoNode.py Sun Apr 12 03:44:14 2015 -0700 +++ b/service/arduinoNode/arduinoNode.py Mon Apr 13 23:30:12 2015 -0700 @@ -5,7 +5,7 @@ """ from __future__ import division import glob, sys, logging, subprocess, socket, os, hashlib, time, tempfile -import shutil +import shutil, json import serial import cyclone.web from rdflib import Graph, Namespace, URIRef, Literal, RDF @@ -72,6 +72,15 @@ self.open() + def description(self): + """for web page""" + return { + 'uri': self.uri, + 'dev': self.dev, + 'baudrate': self.baudrate, + 'devices': [d.description() for d in self._devs], + } + def open(self): self.ser = LoggingSerial(port=self.dev, baudrate=self.baudrate, timeout=2) @@ -285,11 +294,6 @@ subprocess.check_call(['make', 'upload'], cwd=workDir) - -class Index(cyclone.web.RequestHandler): - def get(self): - self.set_header("Content-Type", "text/html") - self.write(open("index.html").read()) class GraphPage(cyclone.web.RequestHandler): def get(self): @@ -330,7 +334,15 @@ stmts = list(rdfGraphBody(self.request.body, self.request.headers)) for b in self.settings.boards: b.outputStatements(stmts) + +class Boards(cyclone.web.RequestHandler): + def get(self): + self.set_header('Content-type', 'application/json') + self.write(json.dumps({ + 'boards': [b.description() for b in self.settings.boards] + }, indent=2)) + def currentSerialDevices(): log.info('find connected boards') return glob.glob('/dev/serial/by-id/*') @@ -362,7 +374,10 @@ log.setLevel(logging.DEBUG) reactor.listenTCP(9059, cyclone.web.Application([ - (r"/", Index), + (r"/()", cyclone.web.StaticFileHandler, { + "path": "static", "default_filename": "index.html"}), + (r'/static/(.*)', cyclone.web.StaticFileHandler, {"path": "static"}), + (r'/boards', Boards), (r"/graph", GraphPage), (r'/output', OutputPage), (r'/arduinoCode', ArduinoCode),