Webinar
EMQX Cloud Message History: From MQTT Topics to SQL Queries →
Back

Connecting ESP32 Devices to AI Agents with Device Agent: From Hardware Control to Voice Interaction

EMQX TeamEMQX Team
Dec 1, 2026AI
Connecting ESP32 Devices to AI Agents with Device Agent: From Hardware Control to Voice Interaction

From voice-enabled devices to desktop assistants, ESP32 boards are finding their way into an increasingly wide range of smart hardware projects. Building on familiar capabilities such as audio, displays, and sensors, EMQ is exploring a development path from hardware connectivity to AI agent applications with Device Agent.

Using a shared laboratory equipment room as an example, this article demonstrates how an ESP32 device can manage equipment usage status, retrieve equipment movement records, and read ambient light levels, with results delivered through voice and on-screen feedback.

ESP32: From Hardware Capabilities to Intelligent Interaction

The ESP32 family supports a wide range of connected and embedded applications. Its popular variants offer developers a rich ecosystem of development options:

  • ESP32-C3 is well suited for connected devices such as sensors and switches.
  • ESP32-C6 supports Wi-Fi 6, Bluetooth LE, and IEEE 802.15.4 connectivity.
  • ESP32-S3 features a dual-core processor, vector instructions, and a rich set of peripheral interfaces, making it suitable for audio, display, and intelligent interaction applications.
  • ESP32-P4 targets more demanding human-machine interaction and multimedia applications, with wireless connectivity provided through an additional solution.

These chips and development boards already give developers a solid hardware foundation. Microphones capture audio, speakers play sound, displays present information, and sensors monitor the surrounding environment.

With the development of large language models (LLMs) and AI agents, however, the scope of development is expanding: How can users interact with these hardware capabilities through natural language, and how can devices carry out tasks based on their actual state?

This demonstration uses an ESP32-S3 development board to connect audio input and output, display functions, and sensor data to Device Agent. The ESP32 handles local data collection and hardware execution, while the Device Agent service, deployed on a computer or server, interprets user requests, retrieves device data, and invokes the corresponding operations. Together, they connect user instructions, device state, and physical actions.

Device Agent: Bringing Device Capabilities into AI Agent Applications

To enable intelligent interaction with a device, an AI agent needs to understand what operations the device supports, what data it can provide, and how to verify the results of an operation.

Device Agent organizes this information into a device model. It describes hardware capabilities through properties, commands, and events, providing a clear basis for interactions between natural language requests and physical devices.

Developers can describe a device in natural language, generate and review its model, and then connect the hardware through MQTT or an SDK. They can also use a simulator to validate interactions before connecting a physical device.

When a user makes a request, the agent selects the appropriate operation based on the device model, prepares the required parameters, and responds using the results returned by the device and its reported data.

For devices already connected to an IoT platform, integration can also be achieved through adapted platform interfaces, allowing developers to reuse existing device models and data.

This approach makes it possible to add AI agent capabilities incrementally to existing hardware projects. Firmware continues to handle data collection, hardware control, and display updates, while the device model provides a unified semantic description of these capabilities. This reduces the need to redefine device functions for different interaction interfaces.

A Practical Scenario: Managing Shared Laboratory Equipment

Consider a room containing shared laboratory equipment used by different people throughout the day.

Typical requirements include:

  • When someone starts using the equipment, others need to know that the room is occupied.
  • When the session ends, the room's status indicator should be reset to available.
  • Before using the equipment, staff may also need to check whether it has been moved recently and review the room's lighting conditions.

To support these tasks, an ESP32 terminal can connect to a status display outside the room, an indicator light, a displacement sensor, and an ambient light sensor. A microphone captures user requests, while a display and speaker provide feedback.

Displaying Equipment Usage Status

When someone starts using the equipment, they can issue a voice command:

Change the display outside the room to "In Use" and turn on the indicator light.

Device Agent invokes the corresponding property-setting operations. The ESP32 updates the display and controls the indicator light, then returns the execution result.

When the session ends, the user can similarly ask the device to change the display to "Available" and turn off the indicator light.

This status is set manually by the user to communicate the room's availability to others.

Checking Equipment Before Use

Equipment movement records help staff verify the equipment's condition before use. For example, they can ask:

Has any equipment movement been detected in the past hour?

The system queries displacement events reported during the specified period and returns the available records. Staff can then investigate the equipment's position, wiring, or installation status if necessary.

Displacement events provide an indication that equipment may have moved. Whether recalibration or maintenance is required still depends on the equipment's specifications and further human assessment.

Ambient light readings provide another source of information for pre-use checks. A user can ask:

Check the current light level and play a notification sound if it is below the configured threshold.

The system retrieves the current reading and compares it against a predefined threshold. If the condition is met, it invokes the sound playback command.

This is an on-demand check, addressing a different requirement from equipment status updates and movement record queries.

Defining Device Capabilities and Creating an AI Agent

To make these operations available through conversation, developers first need to define the terminal's capabilities during development.

In Device Agent, enter a prompt in the device agent creation interface:

Create a laboratory equipment terminal that can control an indicator light, update the text on an external display, play a notification sound, and report equipment displacement events and room light levels for users to query and control through voice interactions.

This prompt guides Device Agent in generating a device model that describes the terminal's capabilities.

Developers can review the generated properties, commands, and events to ensure they match the actual hardware implementation. Once confirmed, they can create the device agent and connect the ESP32.

The earlier examples, such as "Change the display outside the room to In Use," are everyday operational requests made by users after the device has been connected.

In this demonstration, which uses IoT platform integration, the device capabilities are organized as follows:

  • The indicator light and external display text are defined as writable properties.
  • Ambient light readings are reported as sensor data.
  • Equipment movement is represented by displacement events.
  • Playing a notification sound is exposed as an invocable command.

The device model provides a unified definition of these capabilities, allowing subsequent voice requests to map to specific data queries and hardware operations.

Connecting the ESP32 Hardware

Once the device model is confirmed, developers can export the MQTT integration code, adapt it to the ESP32 firmware, and connect it to the existing hardware drivers.

The firmware handles the corresponding operations:

  • When an indicator light property is updated, the firmware invokes the GPIO control logic.
  • When the display text property is updated, the firmware calls the display driver to refresh the content.
  • When a notification sound command is received, the firmware invokes the corresponding audio output logic.
  • Ambient light readings and detected displacement events are reported through MQTT.

The display becomes an output channel through which the AI agent communicates information to people on site.

For example, when a user asks to change the display to "In Use," the agent initiates a property update through the device model. The ESP32 writes the new text to the display, returns the execution result, and reports the actual device state.

This allows developers to reuse existing hardware drivers, with the additional integration logic connecting device messages to hardware operations.

The microphone and speaker are connected through a separate voice communication pipeline.

In this demonstration, voice input uses a push-to-talk interaction: users press and hold a button to start recording and release it to stop. The ESP32 captures audio through the microphone, formats it as 16 kHz, mono, 16-bit PCM, and sends it to the voice service over WebSocket.

The recognized text is then passed into the Device Agent conversation, while the generated voice response is sent back to the terminal and played through the speaker.

The demonstration uses two complementary communication channels:

  • WebSocket handles voice transmission and session control.
  • MQTT handles device data and control messages.

Through the adapted IoT platform interface, Device Agent retrieves device data and executes operations. Both communication channels are associated with the same device.

When a voice request involves changing the indicator light, updating the display, or playing a notification sound, the agent invokes the device capabilities that have already been integrated.

For existing ESP32 projects, developers can start by bringing the device online, reporting its status, and enabling text-based control. Once hardware operations and returned results are verified, voice interaction can be added.

This incremental approach makes it easier to troubleshoot issues across hardware drivers, connectivity, and interaction logic, while validating the complete workflow from microphone input to device execution and speaker feedback.

From Demo to More Intelligent Hardware Applications

Once hardware capabilities are exposed through interfaces that an AI agent can understand and invoke, the same functions can support different ways of interacting with the device and combining tasks.

Users can query ambient light levels, update display text, or combine data retrieval and device control in a single conversation.

As long as the underlying device capabilities and interfaces remain unchanged, developers can typically modify how users express requests or combine existing operations without changing the firmware.

These interactions should always be grounded in actual device data.

For example, when querying equipment movement records, the time range must be clearly specified. A response stating that no movement was detected during a given period is only reliable if the data pipeline is functioning correctly and the records are complete.

Similarly, ambient light checks rely on predefined thresholds, ensuring that the evaluation criteria are clear and the results can be verified.

The same development approach can be extended to a variety of smart hardware applications:

  • Desktop assistants: Integrate temperature and humidity sensors to let users check environmental conditions through voice interactions.
  • Smart control panels: Add natural language interfaces to control lighting, relays, and displays.
  • Device monitoring terminals: Integrate operational data and anomaly events to make device status easier to query.

For ESP32 developers, a practical starting point is an existing hardware project with three basic capabilities: one readable property, one executable command, and one reportable event.

Use Device Agent to define the device model and validate the interactions, then gradually add a microphone, speaker, and display.

In this way, familiar peripherals and firmware can become the foundation for building AI agent-powered hardware applications.

For more information, visit the Device Agent Documentation.

Try EMQX Cloud for Free
Get Started →

Article by

EMQX Team

EMQX Team

The EMQX team develops the EMQX Platform, continuously delivering high-performance, scalable MQTT solutions that bridge IoT systems and AI agents for evolving industry needs.