A WEB Server on the ESP32

WiFi

The WeMos D1 mini ESP32 CPU board offers WiFi access implementing a TCP/IP and full 802.11 b/g/n Wi-Fi MAC protocol (see the ESP32 data sheet) and the ESP32 port of MicroPython offers a network module with the necessary access functions.

Before looking into the WEB server we must first make sure we have Internet access through WiFi.The following screen dump shows an interactive MicroPython session where WiFi access is granted:

wifi_connect.png

Of course you must add your correct WiFi ssid and password. In the above case we also scan the WiFi network to see all access points available. If you use your WeMos D1 CPU at different locations with different WiFi networks you can use this function to figure out to which network you have access and connect to the right network automatically.

In the above screen dump wlan.ifconfig() shows you that you can connect to your ESP32 on the IP address 192.168.0.46.

Here is a small piece of Python code accomplishing network access when the ssid is known:

https://iotworkshop.africa/pub/IoT_Course_English/WEBServerPicoweb/wifi_connect_anonymous.py.txt

A "Hello World!" WEB server

Writing a WEB server from scratch is not a trivial task but then the need of a WEB server is so common that you would expect that some kind soul has done the job for you. On MicroPython you find several WEB servers ready for deployment. I have selected picoweb because it is small enough to be easily studied and it has all the functionality needed for the projects in this course. On the other hand picoweb depends on several modules that are not installed in MicroPython by default. I therefore collected everything that is needed and compiled picoweb into the MicroPython binary making it available for immediate use.

-- Uli Raich - 2020-04-28

Comments

Topic attachments
I Attachment History Action Size Date Who Comment
PNGpng wifi_connect.png r1 manage 194.5 K 2020-04-28 - 08:02 UliRaich  
Texttxt wifi_connect_anonymous.py.txt r1 manage 0.4 K 2020-04-28 - 08:02 UliRaich  
Edit | Attach | Watch | Print version | History: r8 | r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r1 - 2020-04-28 - UliRaich
 
  • Edit
  • Attach
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