|
|
|
#! /usr/bin/python3
|
|
|
|
from http.server import SimpleHTTPRequestHandler
|
|
|
|
import socketserver
|
|
|
|
import logging
|
|
|
|
from led import setLED
|
|
|
|
|
|
|
|
|
|
|
|
logging.basicConfig( format='%(asctime)-15s [%(levelname)s] %(funcName)s: %(message)s', level=logging.DEBUG)
|
|
|
|
|
|
|
|
class LEDHttpRequestHandler(SimpleHTTPRequestHandler):
|
|
|
|
def do_GET(self):
|
|
|
|
logging.debug(f'path= {self.path}')
|
|
|
|
logging.debug('GET: empfangen')
|
|
|
|
logging.debug(f'Request: {self.request}')
|
|
|
|
self.send_response(200)
|
|
|
|
self.send_header('Content-Type:','text/html')
|
|
|
|
|
|
|
|
if 'led=on' in self.path:
|
|
|
|
logging.debug('schalte LED ein')
|
|
|
|
setLED(True)
|
|
|
|
else:
|
|
|
|
logging.debug('schalte LED aus')
|
|
|
|
setLED(False)
|
|
|
|
|
|
|
|
self.wfile.write('<p>LED geschaltet</p>'.encode())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class http_server:
|
|
|
|
def __init__(self):
|
|
|
|
def handler(*args):
|
|
|
|
myHandler(*args)
|
|
|
|
server = HTTPServer(('', 8080), handler)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
logging.debug('MAIN: start')
|
|
|
|
handler = LEDHttpRequestHandler
|
|
|
|
with socketserver.TCPServer(('',9000),handler) as httpd:
|
|
|
|
logging.info('SERVER: start')
|
|
|
|
try:
|
|
|
|
httpd.serve_forever()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|