Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » ESP32 MicroPython Web Server – Sensor Data on Webpage
ESP32 MicroPython

ESP32 MicroPython Web Server – Sensor Data on Webpage

Mamtaz AlamBy Mamtaz AlamUpdated:August 21, 20222 Comments4 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
ESP32 MicroPython Web Server
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Overview: ESP32 MicroPython Web Server

In this article, we are going to learn about ESP32 MicroPython Based Web Server. We will interface DS18B20 Waterproof Temperature Sensor with ESP32 & read the temperature. We will then create a Web Server & Send the DS18B20 Temperature Data to the Web Server. Using the IP Address we will monitor the Sensor data on the Webpage. You can access the Sensor data on your Local Network.

But before beginning, I will highly recommend you to follow the following tutorial to boost up your MicroPython skill. I have explained how you can install MicroPython & use uPyCraft IDE. Similarly, I have also explained how you can interface DS18B20 Temperature Sensor with ESP32 using MicroPython Code.
1. Getting Started with MicroPython on ESP32 using PyCraft IDE
2. Interfacing DS18B20 Temperature Sensor with ESP32 using MicroPython


Bill of Materials

Following are the components required for making the ESP32 MicroPython Web Server Project. All the components can be eaily purchased from Amazon. The components purchase link is given below.

S.N.Components NameQuantityPurchase Links
1ESP32 Board1Amazon | AliExpress
2DS18B20 Temperature Sensor1Amazon | AliExpress
3Resistor 4.7K1Amazon | AliExpress
4Connecting Jumper Wires5Amazon | AliExpress
5Breadboard1Amazon | AliExpress


In my case I am using a MakePython ESP32 Board as this board is cheaper with additional 1.3″ OLED Display and is specially designed for Python support.

MakePython ESP32 Board

To learn more about this board and purchase it online, you can visit this link: MakePython ESP32 Board.


What is Web Server?

A Web Server is server software dedicated to run the software, that can satisfy client requests on the World Wide Web. A web server may contain one or more websites. A web server processes incoming network requests over HTTP and several other related protocols.

The primary function of a web server is to store, process, and deliver web pages to clients. The communication between client and server takes place using the Hypertext Transfer Protocol (HTTP). Pages delivered are most frequently HTML documents, which may include images, style sheets, and scripts in addition to the text content.

A user agent, commonly a web browser or web crawler, initiates communication by making a request for a specific resource using HTTP and the server responds with the content of that resource or an error message if unable to do so.

You can check the following tutorial to learn more about the ESP32 Web Server: ESP32 Weather Station on Web Server


Circuit Diagram & Connections

Here is a circuit diagram for Interfacing DS18B20 Temperature Sensor with ESP32 using MicroPython Code. The digital output pin is connected to ESP32 GPIO22 Pin. A 4.7K Resistor is used as a pull-up resistor & is connected between digital output pin & VCC Pin. If you want to learn more about the DS18B20 Temperature Sensor you can follow this post: Interfacing DS18B20 Temperature Sensor with ESP32.

DS18B20 ESP32 MicroPython

In case if you are using MakePython ESP32 Board, you can do the following connection as shown in the connection diagram below.

Makepython ESP32 DS18B20 MicroPython




MicroPython Code/Program

Now let us check the ESP32 MicroPython Code for Creating Web Server. The code contains two parts.
1. boot.py
2. main.py

The boot.py runs after device starts and immediately sets up multiple configuration options like your network credentials, importing libraries. Similarly, main.py executes immediately after boot.py. It is the main script where we’ll handle the webserver.

boot.py Code

Create a new file in the uPyCraft IDE and save it as boot.py. Then copy the following code and upload it to the ESP32 Board.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
try:
  import usocket as socket
except:
  import socket
  
from time import sleep
from machine import Pin
import onewire, ds18x20
 
import network
 
import esp
esp.osdebug(None)
 
import gc
gc.collect()
 
ds_pin = Pin(22)
ds_sensor = ds18x20.DS18X20(onewire.OneWire(ds_pin))
 
ssid = 'Alexahome'
password = 'loranthus'
 
station = network.WLAN(network.STA_IF)
 
station.active(True)
station.connect(ssid, password)
 
while station.isconnected() == False:
  pass
 
print('Connection successful')
print(station.ifconfig())

main.py Code

Create another file in the uPyCraft IDE and save it as main.py. Then copy the following code and upload it to the ESP32 Board.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
def read_ds_sensor():
  roms = ds_sensor.scan()
  print('Found DS devices: ', roms)
  print('Temperatures: ')
  ds_sensor.convert_temp()
  for rom in roms:
    temp = ds_sensor.read_temp(rom)
    if isinstance(temp, float):
      msg = round(temp, 2)
      print(temp, end=' ')
      print('Valid temperature')
      return msg
  return b'0.0'
  
def web_page():
  temp = read_ds_sensor()
  html = """<!DOCTYPE HTML><html><head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
  <style> html { font-family: Arial; display: inline-block; margin: 0px auto; text-align: center; }
    h2 { font-size: 3.0rem; } p { font-size: 3.0rem; } .units { font-size: 1.2rem; }
    .ds-labels{ font-size: 1.5rem; vertical-align:middle; padding-bottom: 15px; }
  </style></head><body><h2>ESP32 DS18B20 WebServer</h2>
  <p><i class="fas fa-thermometer-half" style="color:#059e8a;"></i>
    <span class="ds-labels">Temperature</span>
    <span id="temperature">""" + str(temp) + """</span>
    <sup class="units">&deg;C</sup>
  </p>
    <p><i class="fas fa-thermometer-half" style="color:#059e8a;"></i>
    <span class="ds-labels">Temperature</span>
    <span id="temperature">""" + str(round(temp * (9/5) + 32.0, 2)) + """</span>
    <sup class="units">&deg;F</sup>
  </p></body></html>"""
  return html
 
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 80))
s.listen(5)
 
while True:
  try:
    if gc.mem_free() < 102000:
      gc.collect()
    conn, addr = s.accept()
    conn.settimeout(3.0)
    print('Got a connection from %s' % str(addr))
    request = conn.recv(1024)
    conn.settimeout(None)
    request = str(request)
    print('Content = %s' % request)
    response = web_page()
    conn.send('HTTP/1.1 200 OK\n')
    conn.send('Content-Type: text/html\n')
    conn.send('Connection: close\n\n')
    conn.sendall(response)
    conn.close()
  except OSError as e:
    conn.close()
    print('Connection closed')




Monitor Sensor Data on ESP32 MicroPython Web Server

After uploading both the code, press the Reset Button on ESP32 Board. The ESP32 will now try connecting to the network using the network credentials. Once connected it will show the IP Address in Shell Window.

Image

You can copy the IP Address and go to any web browser and paste it there. You will see the DS18B20 Sensor Data displayed on Web Page.

ESP32 MicroPython Web Server


Video Tutorial & Guide

Episode 2: MicroPython on ESP32 - Interfacing OLED Display, DS18B20 Sensor & Creating Web Server
Watch this video on YouTube.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleMicroPython: Interfacing DS18B20 Temperature Sensor with ESP32
Next Article ESP8266 NRF24L01 Wifi Gateway with Arduino NRF24L01 Node

Related Posts

LoRa Soil Moisture

LoRa Based Soil Moisture Monitoring on LoRa ESP32 WebServer

Updated:August 20, 202222K
ESP32 MicroPython - Interfacing Ultrasonic Sensor HC-SR04

ESP32 MicroPython – Interfacing Ultrasonic Sensor HC-SR04

Updated:August 21, 20224K
MicroPython ESP32 DHT11

MicroPython: ESP32 with DHT11 Humidity Temperature Sensor

Updated:August 22, 202213K
MicroPython DS18B20 ESP32

MicroPython: Interfacing DS18B20 Temperature Sensor with ESP32

Updated:August 21, 20227K
ESP32 OLED DisplayMicroPython

MicroPython: Interfacing 0.96″ OLED Display with ESP32

Updated:May 26, 20234K
ESP32 MicroPython uPyCraft

MicroPython on ESP32 using uPyCraft IDE – Getting Started

Updated:August 22, 202246K
View 2 Comments

2 Comments

  1. Image
    Andy on January 24, 2023 2:57 PM

    Is uPyCraft IDE the best option for MicroPython development?

    Reply
  2. Image
    Peter on April 20, 2023 11:41 PM

    I had a lot of trouble with uPyCraft. “Install” was awkward, and it was not able to re-establish connection with a running application after a restart or power cycle of the device. Trying Thonny at the moment. It seems much better.

    Reply

CommentsCancel reply

Image
Image
Latest Posts
DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

December 7, 2025
Flight Black-Box Motion Recorder using ESP32 & BMI160

Flight Black-Box Motion Recorder System using ESP32 & BMI160

December 7, 2025
Humidity & Temperature Monitoring using DHT11 & NodeMCU on ThingSpeak

ESP8266 & DHT11 Humidity Temperature Monitor on ThingSpeak

October 19, 2025
IoT based Battery SoC (%) Monitoring System with ESP32

IoT based Battery SoC (%) Monitoring System with ESP32

September 28, 2025
Image

Speed-Run Translations: Making Fast-Moving Meme Videos Accessible Worldwide

September 22, 2025
DIY ESP32 Board for Battery Powered IoT Applications

DIY ESP32 Board for Battery Powered IoT Applications

September 28, 2025
Build IoT DC Energy Meter with ESP32 Web Dashboard

Build IoT DC Energy Meter with ESP32 Web Dashboard

September 5, 2025
Image

The Future of Video Production: Adding Emotion with AI Voice Generators

August 26, 2025
Top Posts & Pages
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • LD2410 Sensor with ESP32 - Human Presence Detection
    LD2410 Sensor with ESP32 - Human Presence Detection
  • ECG Graph Monitoring with AD8232 ECG Sensor & Arduino
    ECG Graph Monitoring with AD8232 ECG Sensor & Arduino
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • How to use ADS1115 16-Bit ADC Module with Arduino
    How to use ADS1115 16-Bit ADC Module with Arduino
  • Designing of MPPT Solar Charge Controller using Arduino
    Designing of MPPT Solar Charge Controller using Arduino
  • Interfacing PMS5003 PM2.5 Air Quality Sensor with Arduino
    Interfacing PMS5003 PM2.5 Air Quality Sensor with Arduino
  • IoT Based Electricity Energy Meter using ESP32 & Blynk
    IoT Based Electricity Energy Meter using ESP32 & Blynk
Categories
  • Arduino Projects (197)
  • Articles (59)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (27)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (199)
    • ESP32 MicroPython (7)
    • ESP32 Projects (76)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (37)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (17)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.
Advertisement