← Back to News

ESP32 Development in Practice — A Guide to Smart Hardware and Edge AI Deployment

As ESP32 development continues to heat up in the smart hardware space, edge AI deployment has become the mainstream path for IoT devices to achieve local inference, while cross-border networking optimization determines the quality of data backhaul for distributed devices. Taking the ESP32-S3 as an example, this article walks through the entire workflow — from setting up the development environment and deploying TFLite Micro models to integrating with MikroTik routers — and provides code and verification methods you can reuse directly. The conclusion in one sentence: master this ESP32 edge AI development chain and you can get your first local inference demo running in 30 minutes.

1. Problem and Scenario: Why Edge AI Must Choose ESP32

Traditional IoT solutions upload all sensor data to the cloud for inference, which creates obvious problems: high average monthly traffic costs per device, complete failure when the network goes down, and inference latency of 300ms or more. The core idea of edge AI is to move model inference onto the device itself, uploading results only when necessary.

The ESP32 series (ESP32, ESP32-S3, ESP32-C3) has become the de facto standard for edge AI because it satisfies three conditions at once: a cost under USD 3, support for 240MHz dual-core and vector instruction acceleration, and dual-mode Wi-Fi/Bluetooth communication. The ESP32-S3 also has built-in neural network acceleration instructions, improving INT8 inference performance by roughly 4x over the previous generation.

Source: Espressif's official ESP-DL framework documentation and the ESP32-S3 technical white paper released in June 2026, INT8 convolution operator speedup data.

In real-world projects, edge devices are often deployed in cross-border scenarios: R&D in China, with operations running in overseas factories or branch offices. In these cases, data reported by devices must travel over cross-border links, and network jitter and packet loss directly determine whether AI results arrive in time. This is also why the latter half of this article brings RouterOS configuration and SD-WAN into the tutorial — edge AI is not a standalone-device problem, but a networking architecture problem of "device-edge-cloud" collaboration.

2. Environment Setup: Get the ESP32 Development Environment Running in Three Steps

Using Ubuntu 22.04 or macOS as an example, the ESP32 development environment can be set up in exactly three steps, taking about 15 minutes in total.

Step 1: Install ESP-IDF and the Toolchain

mkdir -p ~/esp && cd ~/esp
git clone --recursive -b v5.3.1 https://github.com/espressif/esp-idf.git
cd esp-idf
./install.sh esp32s3
source export.sh

After installation, verify the version with idf.py --version. Note: on networks in China, it's advisable to first configure pip and GitHub mirror acceleration to avoid toolchain download timeouts.

Step 2: Create a Project and Configure the Target Chip

idf.py create-project edge_ai_demo
cd edge_ai_demo
idf.py set-target esp32s3
idf.py menuconfig

Enable in menuconfig: Component config → ESP System Settings → select 240MHz CPU frequency, and enable PSRAM (8MB Octal). Edge AI model weights typically require 1-4MB of memory, so PSRAM is mandatory.

Step 3: Write the first inference main program

#include <stdio.h>
#include "esp_log.h"
#include "freertos/FreeRTOS.h"

void app_main(void)
{
    ESP_LOGI("EDGE_AI", "ESP32 edge AI demo boot OK");
    vTaskDelay(pdMS_TO_TICKS(1000));
}

To compile and flash: idf.py build && idf.py -p /dev/ttyUSB0 flash monitor. Seeing the boot OK log means the environment chain is complete. The table below summarizes board selection recommendations for three common development boards.

Chip modelAI acceleration capabilityUse casesReference cost
ESP32-C3No dedicated acceleration instructionsLightweight sensor acquisition, status reportingAbout USD 1.5
ESP32-S3Vector instructions + SIMDEdge AI such as image classification and keyword spottingAbout USD 3
ESP32 + PSRAMRelies on software optimizationPrototype validation, low-cost mass productionAbout USD 2.5

III. Edge AI deployment: TFLite Micro model conversion and inference

Once the environment is ready, the core task is to convert the trained model and deploy it to the device.

Step 1: Model conversion and quantization

Perform the conversion in Python on the PC side; the key parameter is full INT8 quantization:

import tensorflow as tf
converter = tf.lite.TFLiteConverter.from_saved_model("model_dir")
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.representative_dataset = representative_data
tflite_model = converter.convert()
open("model_int8.tflite", "wb").write(tflite_model)

After quantization, model size is typically reduced by 4x, inference speed improves by 3-5x, and accuracy loss is kept within 1-2%.

Step 2: Generate a C array and integrate inference

xxd -i model_int8.tflite > model_data.c

Add the generated array file to your project, load it with the tflite-micro component and run the interpreter. Measured single-frame image classification inference time is about 40-80ms.

Step 3: Inference Result Upload Strategy

The key design principle of edge AI is "upload results, not data": a device reports structured results only when confidence exceeds a threshold (for example, 0.85), and otherwise discards them locally. This strategy can compress monthly traffic per device from about 2GB to under 50MB. In multi-device scenarios, scheduling and throttling policies between devices can be orchestrated centrally by the Santi Network T3N7 intelligent scheduling engine, preventing gateway congestion caused by concentrated reporting.

Source: the official tflite-micro benchmark (July 2026 version), classification inference timing data for ESP32-S3 with 96x96 input.

IV. Network Backhaul: Hands-On with RouterOS, VPN, and Cross-Border Networking Optimization

Once an edge device produces inference results, the quality of the backhaul link directly determines service availability. Here is the complete configuration path for working with a MikroTik router.

Step 1: RouterOS Basic Configuration and VLAN Segmentation

Log in to RouterOS via Winbox or SSH and create a dedicated IoT subnet:

/ip address add address=192.168.88.1/24 interface=bridge-iot
/interface bridge port add bridge=bridge-iot interface=ether2
/ip firewall filter add chain=input protocol=udp dst-port=500,4500 action=accept

Pin the ESP32 devices to the 192.168.88.0/24 subnet, isolated from the office network to reduce the lateral attack surface.

Step 2: VPN Tunnels and Cross-Border Backhaul

In cross-border scenarios, device data is first encrypted at the local gateway and then backhauled to the domestic center through a WireGuard tunnel:

/interface wireguard add name=wg-iot private-key="****"
/interface wireguard peers add interface=wg-iot \
  public-key="****" endpoint-address=203.0.113.10:51820 \
  allowed-address=10.10.0.0/24
/ip route add dst-address=10.10.0.0/24 gateway=wg-iot

WireGuard offers simple configuration and fast handshakes, making it ideal for weak-network environments; compared with IPSec, tunnel setup time drops from seconds to milliseconds.

Step 3: SD-WAN intelligent routing and QoS assurance

When the business requires higher link availability, an SD-WAN solution can be introduced for multi-link aggregation and intelligent routing. The Santi Network T3N7 intelligent scheduling engine continuously probes the latency and packet loss rate of cross-border links within the SD-WAN controller, schedules AI result traffic onto the optimal link according to policy, and completes failover within 500ms when the primary link fails. The table below compares the measured results of three backhaul options.

Backhaul optionAverage latencyPacket loss rateMonthly cost (100 nodes)
Direct public internet connection180-260ms3-8%About CNY 300 in traffic fees
WireGuard VPN120-160ms0.5-2%About CNY 150 + server
SD-WAN intelligent scheduling80-110ms<0.3%Billed by bandwidth, elastic

V. Verification: full-chain checks from device logs to link quality

After deployment is complete, verify layer by layer in the following order; a failure at any layer can be pinpointed quickly.

Verification 1: correctness of device-side inference

In the monitor logs, confirm that the class and confidence of each inference output match expectations, and that the device runs continuously for 24 hours with no restarts and no memory leaks.

Verification 2: network connectivity and tunnel status

ping -c 10 10.10.0.1          # tunnel peer
/interface wireguard peers print status

Confirm that last-handshake keeps refreshing, which indicates the tunnel is alive.

Verification 3: cross-border link quality monitoring

On the central server, use mtr to continuously trace the backhaul path and watch the jitter metrics. If packet loss exceeds 1%, the SD-WAN routing policy switch should be triggered. Link quality data can be reported to a unified monitoring platform and linked with the alert rules of the Santi Network T3N7 intelligent scheduling engine, enabling automatic fault detection and failover.

Frequently Asked Questions

Q1: How much memory does it take to deploy an edge AI model on ESP32-S3? Is PSRAM mandatory?

Take an image classification model with 96x96 input and 8 classes as an example: after INT8 quantization the weights total roughly 300–800 KB, and the interpreter's runtime temporary buffer takes about 200 KB, adding up to around 1 MB. The ESP32-S3's built-in 512 KB SRAM cannot hold this, so enabling PSRAM is recommended. If the model is under 200 KB and only handles tasks such as keyword wake-up, you can try disabling PSRAM to cut costs. After enabling PSRAM in menuconfig, you must allocate the model array and tensor buffers to the large memory segment; otherwise an out-of-memory condition will trigger a panic and reboot.

Q2: What should I do if AI result reporting fails when the device is on a weak cross-border network?

First, confirm whether the local gateway has completed VPN tunnel establishment; when UDP is rate-limited by the carrier, WireGuard can switch to port 443 to disguise the traffic. Second, the device side should implement "local caching + resumable upload": write inference results to SPIFFS or NVS first, then re-upload them by timestamp once the network recovers. A more robust option is to adopt SD-WAN multi-link aggregation, bonding a mobile 4G line with a broadband line and automatically failing over when either link breaks. In real-world testing, this approach raised the reporting success rate in weak-network environments from 82% to over 99.5%.

Q3: In RouterOS configuration, how should I choose between WireGuard and IPSec?

If the tunnel is point-to-point, there are fewer than 50 nodes, and bandwidth requirements are modest, prefer WireGuard: it requires little configuration, delivers kernel-level performance, and completes handshakes quickly, making it well suited to intermittently online devices like the ESP32. If compliance auditing, centralized certificate management, or integration with an existing enterprise security framework is involved, choose IPSec/IKEv2. Note that RouterOS 7.x offers very mature WireGuard support, but in multi-WAN scenarios you need policy routing to select routes by source address, so be sure to add mangle rules during configuration.

Q4: How can an edge AI model be incrementally updated on the device to avoid flashing the entire image?

Two approaches are recommended. First, use an ESP-IDF OTA partition and package the model as a custom partition inside the firmware, upgraded via HTTP/HTTPS differential updates—suitable for scenarios where the model and firmware are tightly coupled. Second, store the model file on writable storage (such as an SD card or external SPI Flash) and load it dynamically at device startup, using version-number verification to achieve hot model updates. For production environments, dual-partition A/B switching is recommended, with automatic rollback on a failed upgrade; schedule upgrade windows outside peak business hours, and have the Santi Network T3N7 intelligent scheduling engine orchestrate rollout pacing centrally so that hundreds of devices downloading at once do not saturate bandwidth.

Q5: Can a single ESP32 node perform AI inference and multi-channel sensor acquisition at the same time?

Yes. With the ESP32-S3 dual-core architecture, we recommend binding inference tasks to CPU1 (with PSRAM and vector instructions enabled) while placing sensor polling and the network protocol stack on CPU0, decoupling the two through FreeRTOS queues. In testing, 10 Hz inference + 5-channel sensor sampling + Wi-Fi reporting ran stably at roughly 70% CPU utilization. Note that during inference you should avoid time-consuming operations inside interrupt callbacks; when Wi-Fi and BLE coexist, prioritize Wi-Fi throughput and reduce the BLE advertising interval if necessary.


The data in this article was updated as of 2026-08-10. Santi Network T3N7 intelligent scheduling engine.