Skip to content

Checking your reading list…

Retry

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

ESP32 Meets AI Agents: Voice-Controlled Hardware with Device Agent

This article demonstrates how to integrate ESP32-S3 with EMQ's Device Agent to create a voice-enabled intelligent agent for a shared instrument room, covering device modeling, MQTT/WebSocket integration, sensor data reporting, and natural language control of displays, indicators, and audio feedback.

ESP32 Family: From Hardware to Intelligent Interaction

The ESP32 family covers diverse connectivity and embedded needs. The classic ESP32 has a rich ecosystem: ESP32-C3 for sensor and switch endpoints; ESP32-C6 adds Wi-Fi 6, Bluetooth LE, and IEEE 802.15.4; ESP32-S3 provides dual-core processing, vector instructions, and rich peripherals for audio, display, and smart interaction; ESP32-P4 targets higher-performance HMI and multimedia, requiring companion wireless solutions. These chips already give developers microphones, speakers, screens, and sensors. The next challenge is letting users invoke these capabilities via natural language and have the device act on its actual state.

Device Agent: Bringing Device Capabilities into Agent Applications

To add intelligent interaction, the agent must understand what operations a device can perform, what data it provides, and how to confirm results. Device Agent organizes this information into a device model using properties, commands, and events, creating a clear semantic bridge between natural language and real hardware. Developers can describe a device in natural language to generate and confirm the model, then connect hardware via MQTT or SDK, or verify interactions with a simulator first. When a user makes a request, the agent selects operations and parameters based on the model, then combines returned results and reported data for feedback. Existing IoT platforms can be adapted to reuse their thing models and device data.

This approach lets developers incrementally add agent capabilities to existing hardware projects: firmware continues handling acquisition, control, and screen refresh, while the device model provides a unified semantic description, avoiding repeated capability definitions across different interaction entry points.

Practical Scenario: Shared Instrument Room State Management

A shared instrument room typically sees rotating users. The scenario requires: signaling room occupancy when a user starts, restoring idle status when finished, checking recent instrument movement before reuse, and verifying room lighting conditions. An ESP32 terminal connects a door status screen, usage indicator light, displacement sensor, and illuminance sensor, receiving requests via microphone and feeding back results via screen and speaker.

Usage Status Indication

When starting, an operator can say: 把门口屏改成「使用中」,并点亮使用指示灯 (Change the door screen to "In Use" and light the usage indicator). Device Agent invokes the corresponding property-set capability; the ESP32 refreshes the screen and controls the indicator, then returns the result. Similarly, ending use changes the screen to "Idle" and turns off the indicator. This status is actively set by the user to inform others.

Pre-Use Checks

Instrument Movement Records serve pre-use verification. A staff member can ask: 过去一小时有没有检测到仪器移动? (Has any instrument movement been detected in the past hour?). The system queries displacement events reported in that time range and returns the records, giving staff leads to check position, wiring, or installation. Movement events provide clues; whether recalibration or maintenance is needed remains a human judgment based on instrument requirements.

Illuminance Data provides another pre-use check. A user can request:

读一下当前照度,低于设定阈值就播放一次提示音

(Read current illuminance; if below the set threshold, play a beep once). The system reads the current value, compares it with a pre-configured threshold, and decides whether to invoke the beep command. This is an active check distinct from the usage indicator and movement query.

Defining Device Capabilities and Creating the Agent

To bring these operations into conversation, developers first define terminal capabilities in Device Agent's creation prompt:

创建一个实验室仪器终端,支持控制指示灯、修改门口屏文字、播放一次提示音,并上报仪器位移事件和房间照度,供用户查询和语音控制。

This prompt generates the device model describing the terminal's capabilities. Developers verify the generated properties, commands, and events against the hardware implementation, then create the device agent and connect the ESP32. The earlier natural-language statements (e.g., "Change the door screen to 'In Use'") become the daily operational requests users send to the device agent after onboarding.

In the demonstrated IoT platform integration, the indicator light and door screen text map to writable properties, illuminance is reported as sensor data, instrument movement maps to displacement events, and playing a beep is a callable command. The device model gives these capabilities a unified definition so subsequent voice requests map to concrete data queries and hardware actions.

Connecting the ESP32 Hardware Pipeline

After model confirmation, developers export MQTT access code, adapt it to the ESP32 firmware, and hook it into existing drivers:

On indicator light property update, firmware calls GPIO control logic.

On display text property update, firmware invokes the screen driver to refresh content.

On beep command receipt, firmware triggers the audio output logic.

Sensor-collected illuminance and detected displacement events are reported via MQTT.

The screen becomes the agent's outlet for presenting information on-site. When a user says "Change the door screen to 'In Use'", the agent initiates a property update through the device model; the ESP32 writes the text to the screen and returns execution results while reporting actual state. Original drivers are reused; new access logic simply connects device messages to hardware actions.

Microphone and speaker connect via a voice pipeline. The demo uses push-to-talk: hold to record, release to stop. The ESP32 formats microphone audio as 16 kHz, mono, 16-bit PCM and sends it over WebSocket to a speech service; recognition results enter the Device Agent session; generated voice replies return to the terminal for speaker playback.

The entire demo uses two coordinated connections: WebSocket carries voice exchange and session control; MQTT carries device data and control messages. Device Agent queries data and executes operations through the adapted IoT platform interface, both channels bound to the same device. Voice requests that involve changing the light, screen, or playing a beep still invoke the already-integrated device capabilities.

For existing ESP32 projects, the recommended incremental path is: first bring the device online with state reporting and text control, verify hardware actions match returned results, then add voice. This isolates driver, connectivity, and interaction issues and progressively validates the full loop from microphone input to device execution to speaker feedback.

From Demo to More Smart Hardware Applications

Once hardware capabilities are organized into interfaces an agent can understand and invoke, the same function set supports more interaction expressions and task combinations. Users can query illuminance alone, request screen text changes, or combine queries and controls in one dialogue. As long as implemented device capabilities and interfaces remain stable, adjusting expressions or recombining operations typically requires no firmware changes.

These interactions always rely on actual device data. For example, querying instrument movement requires a clear time range; only with a complete data pipeline and records can the absence of events be stated as "no movement detected in that period." Illuminance checks use pre-configured thresholds, ensuring clear, verifiable judgment conditions.

The same development pattern extends to other projects: adding temperature/humidity sensors to a desktop assistant for voice-based environment queries; giving smart panels natural-language control entries for lights, relays, and displays; connecting device-status terminals to runtime data and anomaly events for easier status inquiries.

For ESP32 developers, the advice is to start from a working hardware project, pick one queryable state, one executable action, and one reportable event, use Device Agent to model and verify interaction, then gradually integrate microphone, speaker, and screen. Familiar peripherals and firmware thus become the starting point for building agent applications.

Device Agent documentation:

https://docs.emqx.com/zh/device-agent/latest/
About this article

For questions about attribution, corrections or content rights, please contactadmin@besthub.devand we will review it promptly.

WebSocketIoTVoice InteractionMQTTEmbedded AISmart HardwareESP32Device Agent

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion