Climate control on ESP32-C3: access point, AHT10 sensor polling, and WebSocket web UINote · digest for November 3
Macro shot of an ESP32-C3 microcontroller with a connected AHT10 sensor and a smartphone web UI display on a workbench.
Note2 sections≈ 4 min

Climate control on ESP32-C3: access point, AHT10 sensor polling, and WebSocket web UI

In modern home automation and the Internet of Things (IoT), a troubling trend has emerged: manufacturers try to tie even the simplest thermostat or humidity relay to a proprietary Chinese or American cloud. The moment a provider shuts down its servers, geo-blocks an app, or your home router simply blinks, the automation in a greenhouse, home conservatory, or server rack turns into a useless piece of plastic.

The open-source esp32c3-webUI project by developer TINLAB offers an uncompromising counterexample: a completely autonomous climate-control module built on the energy-efficient ESP32-C3 chip with an open RISC-V CPU architecture (160 MHz clock speed).

The device operates on a Zero-Cloud principle: the microcontroller spins up its own protected Wi-Fi access point (SoftAP), runs an embedded web server, and maintains a two-way real-time socket. To adjust thresholds or check the current temperature, you just connect from a smartphone to the device's local network and open a browser.

Hardware: I2C bus and MOSFET power switches

The device schematic is designed for maximum assembly simplicity and budget-friendly components:

  • Compute core: an ESP32-C3 SuperMini or Zero board with a built-in 2.4 GHz radio module.
  • Microclimate sensor: a precision digital AHT10 (or AHT20) sensor measuring temperature from -40 to +85 °C and relative humidity from 0 to 100%. It connects over a standard two-wire I2C bus (just four lines total: 3.3V power, GND ground, SDA data, and SCL clock).
  • Power switching: instead of noisy electromechanical relays, quiet N-channel MOSFETs drive 12V/24V loads (cooling fans, heating mats, humidifiers).

The hardware pinout looks like this:

AHT10 sensor:
VCC  -> 3.3V (ESP32-C3)
GND  -> GND  (ESP32-C3)
SDA  -> GPIO 4 (hardware I2C SDA bus)
SCL  -> GPIO 5 (hardware I2C SCL bus)

MOSFET power switches:
Heater gate     -> GPIO 6 (via 220 Ohm resistor, 10 kOhm pull-down to GND)
Humidifier gate -> GPIO 7 (via 220 Ohm resistor, 10 kOhm pull-down to GND)

Live telemetry over WebSocket and hysteresis controller

Static UI files (HTML, CSS, and Vanilla JavaScript) are packed into the microcontroller's flash memory (LittleFS filesystem). On the first request, the browser downloads the static assets in fractions of a second, after which communication switches to a persistent WebSocket channel.

Every 5 seconds, the controller polls the AHT10 sensor and broadcasts a JSON packet to all connected clients:

// Client-side script for interacting with ESP32-C3 over WebSocket
let socket;

function initWebSocket() {
  const gateway = `ws://${window.location.hostname}/ws`;
  socket = new WebSocket(gateway);

  socket.onmessage = (event) => {
    const data = JSON.parse(event.data);
    
    // Reactive DOM update of sensor readings
    document.getElementById('temp-value').innerText = `${data.temperature.toFixed(1)} °C`;
    document.getElementById('hum-value').innerText = `${data.humidity.toFixed(1)} %`;
    
    // Active state indication for power relays
    document.getElementById('heater-indicator').classList.toggle('active', data.tempRelay);
    document.getElementById('hum-indicator').classList.toggle('active', data.humRelay);
  };

  socket.onclose = () => {
    // Automatic reconnection on Wi-Fi signal loss
    setTimeout(initWebSocket, 2000);
  };
}

window.addEventListener('load', initWebSocket);

The firmware implements a two-position controller with configurable hysteresis. It prevents constant switch chattering when temperature fluctuates near the setpoint. Logic reversal is supported: heating mode (turns on when dropping below the setpoint) and cooling mode (turns on when exceeding the threshold). All settings are saved to the microcontroller's non-volatile memory (NVS), so parameters aren't lost on power loss.

Fighting parasitic chip self-heating

Keep in mind: during active Wi-Fi packet transmission, the ESP32-C3 die heats up 2–4 degrees above ambient air temperature. Never mount the AHT10 sensor board flush against the microcontroller inside a closed enclosure. Run the sensor out of the case on a separate four-wire ribbon cable 15–20 cm long into a zone of natural air convection.

The result is a reliable autonomous unit immune to internet outages, port blocks, and external router failures.

Want a deep diveVotes help us choose what to break down in detail. This material has 0 votes.
Sources · 3