Skip to content
Snippets Groups Projects
Commit 22c395e5 authored by Michael Ensslin's avatar Michael Ensslin
Browse files

add qrcode server and hardware interface

parent 88999021
No related branches found
No related tags found
No related merge requests found
File moved
File moved
File moved
File moved
File moved
File moved
#!/usr/bin/env python3
from http.server import (
HTTPServer,
BaseHTTPRequestHandler
)
import time
import serial
spacelock = serial.Serial('/dev/ttyS0', baudrate=9600)
def send_code(code):
print("sending code: %r" % (code,))
spacelock.write((code + '\n').encode())
time.sleep(0.1)
reply = spacelock.read(spacelock.in_waiting).decode(errors='replace')
print("reply: %r" % (reply,))
return reply
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
result = ''
try:
if self.path.startswith('/send/'):
result = send_code(self.path[6:])
except BaseException as exc:
result = str(exc)
self.send_response(503)
else:
self.send_response(200)
self.send_header("Content-type", "text")
self.end_headers()
self.wfile.write(result.encode('utf8', errors='replace'))
if __name__ == '__main__':
httpd = HTTPServer(('', 8000), RequestHandler)
httpd.serve_forever()
#!/usr/bin/env python2
import argparse
import base64
import hashlib
import pprint
import subprocess
import cbor
import zbar
cli = argparse.ArgumentParser()
cli.add_argument('device')
cli.add_argument('--debug', action='store_true')
args = cli.parse_args()
# create a Processor
proc = zbar.Processor()
# configure the Processor
# proc.parse_config('enable')
proc.parse_config('disable')
proc.parse_config('qrcode.enable')
# initialize the Processor
proc.init(args.device, enable_display=args.debug)
if args.debug:
proc.visible = True
def send(text):
subprocess.call(['curl', 'http://localhost:8000/send/' + text])
# read at least one barcode (or until window closed)
while True:
proc.process_one()
for symbol in proc.results:
message = symbol.data
print("Message:\n%s" % (pprint.pformat(message),))
send(message)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment