Created
November 7, 2020 07:00
-
-
Save vinkmar/4884e2d47eecddc1fe6881f7f9bf2763 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import BaseHTTPServer | |
import urllib | |
from microdotphat import write_string, clear, show | |
# This is a really simple HTTP server for displaying text to the | |
# Pimoroni Micro Dot pHAT. Once the server is running: | |
# | |
# http://127.0.0.1:8000/? | |
# => clears the display | |
# | |
# http://127.0.0.1:8000/?hello | |
# => puts "hello " on the display | |
# | |
# http://127.0.0.1:8000/123456789 | |
# => puts "123456" on the display | |
class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler): | |
def do_GET(self): | |
if self.path[0:2] == "/?": | |
self.send_response(200) | |
content = 'OK' | |
self.send_header("Content-Type", "text/plain") | |
self.send_header("Content-Length", str(len(content))) | |
self.end_headers() | |
self.wfile.write(content.encode("utf-8")) | |
write_string(urllib.unquote(self.path)[2:8], kerning=False) | |
show() | |
else: | |
self.send_response(404) | |
self.end_headers() | |
server_address = ('', 8000) | |
httpd = BaseHTTPServer.HTTPServer(server_address, MyHandler) | |
httpd.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment