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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.