Skip to content

Instantly share code, notes, and snippets.

@vinkmar
Created November 7, 2020 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinkmar/4884e2d47eecddc1fe6881f7f9bf2763 to your computer and use it in GitHub Desktop.
Save vinkmar/4884e2d47eecddc1fe6881f7f9bf2763 to your computer and use it in GitHub Desktop.
#!/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