How to do it...

Follow these steps to learn how to create a web handler module:

  1. Run the following lines of code in the REPL:
>>> from netcheck import wait_for_networking
>>> import socket
>>> 
>>> HTTP_PORT = 80
>>> TCP_BACKLOG = 0
>>> BASE_TEMPLATE = """\
... <!DOCTYPE HTML>
... <html lang="en">
... <head>
...     <title>MicroPython</title>
...     <meta charset="UTF-8">
...     <link rel="icon" href="data:,">
...     <meta name="viewport" content="width=device-width">
... </head>
... <body>
... %s
... </body>
... </html>
... """
>>> 
  1. We have created a variable called BASE_TEMPLATE that will act as a generic template. Now, we can fill its body tag with any content we desire. The following block of code defines socket_listen, which does the initial socket ...

Get MicroPython Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.