Page 1 of 1

How to run Microdot webframework

Posted: Tue Sep 14, 2021 8:13 pm
by newbie
Dear forum,

I'm more or less new to Python and especially to MicroPython.

My aim is to have a small webserver running on an ESP8266 connected to my local network, so I can access it any time from my smart phone. At the end of the day some live sensor readings should be shown on the webpage and I would like to control some GPIOs by means of "Push the Button".

I started the project using an old Raspberry Pi which runs a Flask webserver. For now all basic functionalities are implemented, I guess. And they work. Due to it's low prize I would love to do the same with the ESP8266.

There are some few examples on how to use Microdot, but I actually found no information about how to RUN it. According to a Git question how to install it https://github.com/miguelgrinberg/microdot/issues/13 I just copied the file microdot.py to my device. Now I have boot.py, main.py and microdot.py.

After running the boot.py script in Thonny I can see the device actively registered in my routers device list. But when I run the main.py, which only contains the code from this Microdot example https://github.com/miguelgrinberg/micro ... s/hello.py it throws an error "cannot import name Microdot"

I highly appreciate any help on this, how to execute the code and get this little example running.


Many thanks and best regards
Nico

Re: How to run Microdot webframework

Posted: Thu Jan 27, 2022 3:24 am
by jbar
Nico were you able to get your Microdot program to run? I'm trying to do something similar - turn relays on/off depending on temperature. I've got the relay control part programmed, but having issues using Microdot; as you said there are very few examples out there. If you could share your Microdot implementation I'd appreciate it.
Tks,
John

Re: How to run Microdot webframework

Posted: Sat Feb 05, 2022 3:57 am
by larsks
It seems to work for me without a problem. I start by copying "microdot.py" to the board. I'm using an ESP8266, but the process should be similar on other systems. You can test that things are working by trying to import the module from the REPL:

Code: Select all

>>> import microdot
If that works, the example code should work just fine. If I drop the following into "hello.py":

Code: Select all

from microdot import Microdot

app = Microdot()

@app.route('/')
def hello(request):
    return 'Hello, world!'

app.run()
And then from the REPL:

Code: Select all

>>> import hello
I can then access the server:

Code: Select all

$ curl http://192.168.1.193:5000
Hello, world!