Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

ESP8266/ESP32-based WiFi access point using MicroPython

By Nikhil Agnihotri July 29, 2022

Many IoT applications are controlled with the help of a webpage or an HTML website running within a Local Area Network (LAN) or Wireless Local Area Network (WLAN). Some examples of such IoT applications include home automation, office automation, and smart farming. The HTML webpage or website controlling the things is hosted on a microcomputer or microcontroller. The WiFi development boards like ESP8266 and ESP32 provide a WiFi networking interface where the board can act as both a WiFi station or WiFi access point. Check out how to connect ESP8266/ESP32 to a WiFi connection using MicroPython network module. Whether configured as a WiFi station or WiFi access point, MicroPython ports, including ESP8266 and ESP32 can host HTML webpages using the MicroPython socket module. You can check out how to configure ESP8266/ESP32 or other MicroPython ports as TCP server and TCP clients. As a TCP server, ESP8266/ESP32/any MicroPython port can host a webpage.

As a TCP server, we connected ESP8266/ESP32 to a WiFi modem/router where other devices could access the webpage hosted by ESP8266/ESP32 via the internet. The devices could receive commands or sensor data from the ESP8266/ESP32 hosting server all through the internet. In this case, the host web application for home automation or any IoT project is routed by the modem/router between the ESP8266/ESP32 server and the other nodes of the IoT network.

For an IoT application in which all the nodes of the IoT network are deployed locally or are within the range of LAN or WLAN, this network configuration can lead to an avoidable failure. In case the modem/router gets faulty, or the internet connection from your internet service provider (ISP) is suspended due to some fault, the complete IoT application will shut down because the IoT devices could not communicate with each other in the absence or failure of internet connection.

MicroPython ESP8266/ESP32 hosting a HTML app as WiFi station

However, we can avoid such failure by making the ESP8266/ESP32 or other MicroPython port as an independent WiFi access point hosting the web application, so that various nodes could access the IoT application directly with the hosting server( i.e. ESP8266/ESP32, instead of accessing the IoT application via the internet).

MicroPython ESP8266/ESP32 hosting a HTML app as WiFi access pointIn this project, we will demonstrate how to configure ESP8266/ESP32 or any MicroPython port as a WiFi access point and host a webpage directly from the access point.

Components required

  1. ESP8266/ESP32 x1
  2. ESP8266/ESP32 USB cable x1
  3. Computer/Laptop (for programming ESP) x1
  4. Smartphone (to access web application) x1

Circuit connections
You do not need to make any circuit connections. You only need to have a MicroPython software development tool like uPyCraft IDE or Thonny IDE ready and upload MicroPython firmware to ESP8266/ESP32. Finally, you need to upload MicroPython script for this project to ESP8266/ESP32. The script itself will handle both making ESP8266/ESP32 as a WiFi access point and hosting an HTML webpage. Once the script is loaded, the board can be secured in a case and deployed within an IoT application intended to run within WLAN.

Getting ESP8266/ESP32 ready
Before continuing, you must have a MicroPython IDE ready to write, edit and upload codes. You may use uPyCraft IDE or Thonny IDE for software development. With the help of the respective IDE, you must have uploaded the MicroPython firmware to ESP8266 or ESP32. Check out how to get uPyCraft IDE ready and upload MicroPython firmware to ESP8266/ESP32.

MicroPython script

How project works
With the help of a network module, the ESP8266/ESP32 is configured as a WiFi access point instead of a WiFi station. When ESP8266/ESP32 is configured as a WiFi access point, the board can be directly accessed by the other IoT nodes using a WiFi networking interface instead of accessing the board via the internet.

A sample HTML page is designed within the MicroPython script. The HTML page is stored as a string enclosed in double quotations. Since double-quoted strings in both standard Python and MicroPython are immutable, we can host static webpage using such MicroPython structures. Then, the only way we can make an HTML page interact with the hosting server is using HTML form elements like buttons.

Finally, the ESP8266/ESP32 access point is configured as a TCP server using sockets that delivers the webpage whenever the local IP address of ESP8266/ESP32 is requested using an HTTP header by a device connected ESP8266/ESP32 access point.

The code
The MicroPython script begins with importing the socket module in the event the socket module is not found. Next, the network module is imported for configuring the WiFi interface on ESP8266/ESP32. The esp module is imported, and debug is set to none using esp.osdebug() method. The gc module is imported, and garbage collection is explicitly enabled using gc.collect() method.

The variables SSID and password are defined to store the SSID and Network key of the ESP8266/ESP32 server. An object of WiFi networking interface ap_if is instantiated using the network.WLAN() method, which is configured to the WiFi access point. The networking interface is activated by calling active() method and configured to create the SSID and password using config() method. Now, any device can connect to the ESP8266/ESP32 access point with the given SSID and network key. You can choose any SSID and network key of your choice. The SSID and network key are assigned ‘MicroPython-AP’ and ‘eeworldonline’, respectively, in this project. Note that both SSID and password are assigned mutable strings. The SSID will show as a WiFi connection in the WiFi tab of computers and smartphones. The embedded devices can connect to the ESP8266/ESP32 access point by explicitly programming them to connect with the given SSID and password.

The script is made to pass until the WiFi access point is activated. Once the access point is activated, a message ‘connection successful’ is printed to the console. Immediately next, the network parameters of the access point are printed to the console using ifconfig() method.

The function web_page() is defined to deliver the HTML page hosted by the ESP8266/ESP32. In this function, the HTML code of the webpage is stored as an immutable string in a variable HTML. A socket object is instantiated with the socket.socket() method to use IPv4 internet protocol and TCP network at the networking layer of TCP/IP stack. The socket is bound to localhost and port number 80 using socket.bind() method. The socket is activated to listen for incoming TCP connections using the socket.listen() method.

In an infinite while() loop, the socket is made to accept connections from devices connected to the access point using the socket.accept() method. As the ESP8266/ESP32 server accepts a connection, the IP address of the connecting device is printed to the console. The HTTP GET request received from the accepted connection is stored in a variable request.  The received HTTP request from the accepted connection is also printed to the console. The webpage returned by the function web_page() is stored in a variable response and sent to the requesting connection using send() method. The connection is closed using the close() method. The loop continues infinitely, looking for new devices requesting a connection with ESP8266/ESP32 TCP server and delivering the webpage as the localhost the connected device requests IP address.

Result
Upload and run the MicroPython code as a main.py file to ESP8266/ESP32. On running the ESP8266/ESP32 access point, It is displayed as one of the available WiFi connections on a smartphone or computer, as shown in the image below.

Connect the access point by entering the network key defined in the MicroPython code. The ESP8266/ESP32 server has printed the localhost IP address to the console, as shown in the image below.

To open the webpage hosted by the ESP8266/ESP32 TCP server, open a web browser and write the IP address of ESP32/ESP8266 in the address bar, and press Enter. This will send a request from the web client (browser) on the smartphone or computer to the ESP8266/ESP32 server, as shown in the image below.

In response to the request, ESP8266/ESP32 sends the webpage to the web client (browser) of the smartphone/computer, which will be loaded as following.

Note that a WiFi access point on ESP8266/ESP32 using MicroPython cannot operate as a WiFi repeater. MicroPython does not support NAT or IP routing.

 

You may also like:


  • Getting started with MicroPython on ESP8266

  • How to use MicroPython with ESP8266 and ESP32 to connect…

  • How to use ESP8266/ESP32 as a TCP server and client…

  • MicroPython – I2C protocol in ESP8266 and ESP32

  • What is MicroPython?

Filed Under: ARM, Electronic Projects, ESP8266, Python, Tech Articles, Tutorials
Tagged With: arm, esp8266, MicroPython, MicroPython WiFi
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Reducing "shoot-through" in offline Full Bridge SMPS?
  • High Side current sensing
  • How to simulate power electronics converter in PSpice?
  • Voltage mode pushpull is a nonsense SMPS?
  • Layout IRN reduction in Comparator

RSS Electro-Tech-Online.com Discussions

  • Back to the old BASIC days
  • Parts required for a personal project
  • PIC KIT 3 not able to program dsPIC
  • Failure of polypropylene motor-run capacitors
  • Siemens large industrial PLC parts

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • What is AWS IoT Core and when should you use it?
  • AC-DC power supply extends voltage range to 800 V DC
  • Infineon’s inductive sensor integrates coil system driver, signal conditioning circuits and DSP
  • Arm Cortex-M23 MCU delivers 87.5 µA/MHz active mode
  • STMicroelectronics releases automotive amplifiers with in-play open-load detection

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe