ESP32

ESP32 Web Serial: Communicate with ESP32 Using Your Browser

ESP32 Web Serial Communication ESP32 Device Web Browser

The Web Serial API opens up exciting possibilities for ESP32 projects by allowing direct communication between your microcontroller and web browser. No need for additional software or drivers - just your browser and ESP32!

What is Web Serial?

Web Serial API is a powerful browser feature that enables web applications to communicate directly with serial devices connected to your computer. For makers and hobbyists, this means you can create interactive web interfaces for your ESP32 projects without installing any special software.

Browser Support

Chrome 89+

Edge 89+

Not Supported

Not Supported

ESP32 Setup

Hardware Requirements

  • ESP32 Development Board
  • USB Cable (for programming and serial communication)
  • Computer with Chrome/Edge browser

Arduino Code Example

ESP32_WebSerial.ino

void setup() {
    Serial.begin(115200);
    Serial.println("ESP32 Web Serial Example");
}

void loop() {
    // Send sensor reading every second
    float temperature = temperatureSensor.readCelsius();
    Serial.println(temperature);
    delay(1000);
}

Web Implementation

script.js

async function connectSerial() {
    try {
        const port = await navigator.serial.requestPort();
        await port.open({ baudRate: 115200 });
        
        const reader = port.readable.getReader();
        
        while (true) {
            const { value, done } = await reader.read();
            if (done) break;
            
            const decoded = new TextDecoder().decode(value);
            console.log(decoded);
        }
    } catch (error) {
        console.error('Error:', error);
    }
}

Connecting to Device

Learn how to establish a connection between your ESP32 and web browser using the Web Serial API.

Sending/Receiving Data

Understand the methods for sending commands to your ESP32 and receiving sensor data in real-time.

Example Projects

Further Reading

Explore additional resources and documentation to enhance your ESP32 Web Serial projects.