create new tag
view all tags

The microdot web server framework

In contrast to picoweb, microdot supplies extensive documentation. It is a good idea to read this documentation carefully and compare it with the example programs provided.

You can download the microdot repository from github: https://github.com/miguelgrinberg/microdot.
In order to run the examples using the modules included in your MicroPython interpreter, you must make some minor changes to them:

  • when importing microdot please replace
    • from microdot import Microdot by from microdot.microdot import Microdot
      The same is true for the other modules (microdot_asyncio, microdot_ssl, microdot websockets ...)
  • You should connect to your WiFi network, before starting the server:
    • from wifi_connect import connect, getIPAddress
    • connect(ssid="yourSSID",password="yourPassword")
  • Please start the server with
    • app.run(debug=True,host=getIPAddress,port=80) # debug=True is optional, host defines the IP address of your server, port 80 is the standard HTTP port
  • You may add the following print statement before app.run, which will produce a link allowing you to easily start the WEB browser with the correct server address:
    • print("Starting WEB server on http://" + getIPAddress())

The microdot exercises

You can implement the same programs as shown on the WEB Server Picoweb page also with microdot. While picoweb does not provide support for web sockets, microdot does. Please git it a try, starting off with the examples provided in the github repository. The exercise sheet (A WEB server) is now based on microdot.

Server side events on microdot

microdot does not support server side events out of the box. When using server side events, your web server should first send:

"HTTP/1.0 200 OK\r\n"
"Content-Type: text/event-stream\r\n"

before sending a stream of information.

I added a method send_evt_src_header() to the Microdot class, which does exactly this. After calling send_evt_src_header() you may return an iterator, which will repeatedly send information to the client (see the Fibonacci example in the documentation).

-- Uli Raich - 2022-11-12


Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2022-11-16 - UliRaich
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback