Tags:
create new tag
view all tags

Installing the picoweb server

The description of picoweb on its git repository explains it as follows:

picoweb is a "micro" web micro-framework (thus, "pico-framework") for radically unbloated web applications using radically unbloated Python implementation, Pycopy, https://github.com/pfalcon/pycopy .

As you can see, it is designed to run of pycopy, a fork of standard MicroPython, which we use on our ESP32 micro-controller. It depends on several packages, which are normally not part of the standard MicroPython binary such that we either install these dependencies with upip or, better, freeze them into a custom MicroPython binary.

picoweb depends on:

  • utemplate
  • uasyncio
  • pkg_resources
  • ulogging
In order to make these packages available I copy them into the modules directory of the esp32 MicroPython port:

esp32Modules.png

utemplate can be found at https://github.com/pfalcon/utemplate

uasyncio is part of micropython-lib but need a small modification (the awritestr method must be added):

uasyncioMod.png

pkg_resources is the version found in micropython-lib

ulogging is logging, found in micropython-lib, renamed ulogging

As you can see, we also copied picoweb itself into the modules directory. After compiling MicroPython all these modules will be available for use.

Running the WEB server

In the picoweb repository you will find a series of examples: In the picoweb directory you find example_webapp.py and example_webapp2.py, where example_webapp2.py is essentially a subset of example_webapp.py. There is also an "examples" directory with mode examples.

In order to make this example run you have to

  • create a directory called templates on the ESP32 file system and copy squares.tpl into it
  • create the wifi_connect file (see the connect to WiFi description in https://techtutorialsx.com/2017/09/01/esp32-micropython-http-webserver-with-picoweb)
  • modify yourNetworkName and yourNetworkPassword to adapt the script to your WiFi SSID and password and upload the modified script to the ESP32
  • on the ESP32:
    import wifi_connect
    wifi_connect.connect()
    will connect to your WiFi network and print the IP address of the WEB server.
  • In example_webapp.py modify
    app = picoweb.WebApp(__name__, ROUTES) to app = picoweb.WebApp(None, ROUTES)
  • add host="xxx.xxx.xxx.xxx" to app.run where xxx.xxx.xxx.xxx must be replaced by the IP address you get from wifi_connect. In may case:
    app.run(debug=1,host="192.168.1.70")
  • copy example_webapp.py to the ESP32
  • on the ESP32:
    import picoweb
    will start the WEB server
A few screen dumps show the procedure:

First we run wifi_connect.connect() and check the IP address obtained:

picowebRun.png

As ca be seen from the screen dump above, the IP address obtained is 192.168.1.70. This address is added to the app:run (debug=1) called as described above. When importing example_webapp the WEB server is started (see screen dump above). We can also see that port 8081 is used for the WEB server. This URL (192.168.1.70:8081) we enter into the WEB browser and get:

picowebExApp.png

Clicking on squares will display the first 5 square numbers as calculated in templates/squares.tpl:

squares.png

When clicking on source we see the source file of example_webapp:

picowebPrintFile.png

This tells us that the WEB server is now up and running and we can now continue testing the examples in the examples directory before putting our attention to the camera part of the project.

-- Uli Raich - 2020-01-24

Comments

Topic attachments
I Attachment History Action Size Date Who Comment
PNGpng esp32Modules.png r1 manage 23.7 K 2020-01-24 - 14:32 UliRaich  
PNGpng picowebExApp.png r1 manage 30.0 K 2020-01-25 - 10:10 UliRaich  
PNGpng picowebPrintFile.png r1 manage 94.3 K 2020-01-25 - 10:03 UliRaich  
PNGpng picowebRun.png r1 manage 48.7 K 2020-01-25 - 10:02 UliRaich  
PNGpng picowebStart.png r1 manage 29.6 K 2020-01-25 - 10:02 UliRaich  
PNGpng squares.png r1 manage 32.5 K 2020-01-25 - 10:03 UliRaich  
PNGpng uasyncioMod.png r1 manage 36.4 K 2020-01-24 - 14:32 UliRaich  
PNGpng wifiConnect.png r1 manage 45.9 K 2020-01-25 - 10:02 UliRaich  
Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2020-01-25 - 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