Alle Dateien aus dem Pythonkurs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB

2 years ago
#! /usr/bin/python3
from http.server import SimpleHTTPRequestHandler
import socketserver
2 years ago
import logging
from led import setLED
2 years ago
logging.basicConfig( format='%(asctime)-15s [%(levelname)s] %(funcName)s: %(message)s', level=logging.DEBUG)
2 years ago
class LEDHttpRequestHandler(SimpleHTTPRequestHandler):
2 years ago
def do_GET(self):
logging.debug(f'path= {self.path}')
2 years ago
logging.debug('GET: empfangen')
logging.debug(f'Request: {self.request}')
2 years ago
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())
2 years ago
class http_server:
2 years ago
def __init__(self):
def handler(*args):
myHandler(*args)
server = HTTPServer(('', 8080), handler)
2 years ago
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