IoT Architecture Based on ESP32 and AWS Fully Managed Services: Efficient Device-Cloud-APP Interconnection with MQTT + WebSocket

IoT Architecture Based on ESP32 and AWS Fully Managed Services: Efficient Device-Cloud-APP Interconnection with MQTT + WebSocket

Using ESP32 + MQTT (Device to Cloud) + WebSocket (Cloud to APP) architecture, and introducing AWS Serverless + AWS IoT Core. This is a modern, scalable, and low-maintenance IoT architecture choice.

Covers low power consumption for devices, optimization of AWS cloud serverless architecture, and IoT Core access design.

1. Overall Architecture Diagram

Plain Text [ESP32] ←→ [AWS IoT Core] ←→ [AWS Lambda] ←→ [API Gateway/WebSocket API] ←→ [APP] [DynamoDB] [Amazon Cognito] Status Cache/Offline Commands

2. Low Power Design for Device Side (ESP32) (Compatible with AWS IoT)

1. MQTT Settings (ESP32 Connects to AWS IoT Core)

Use MQTT over TLS (as required by AWS);

Connect to AWS IoT each time it wakes up:

Authenticate using X.509 certificate;

Quickly report status after connecting;

Subscribe to command topics, process, and then sleep;

Use QoS 1 to ensure reliable command delivery.

Recommended topic design:

IoT Architecture Based on ESP32 and AWS Fully Managed Services: Efficient Device-Cloud-APP Interconnection with MQTT + WebSocket

2. Summary of Low Power Strategies (ESP32)

IoT Architecture Based on ESP32 and AWS Fully Managed Services: Efficient Device-Cloud-APP Interconnection with MQTT + WebSocket

3. Cloud Architecture (Based on AWS Serverless + IoT Core)

1. AWS IoT Core Access

Authentication Method: ESP32 connects to AWS IoT using X.509 certificate;

Device Shadow:

Supports persistence and synchronization of device status;

Suitable for querying device online/offline status and latest reported data;

Rules Engine (IoT Rules):

Triggers when the device publishes a message:

Write data to DynamoDB;

Invoke AWS Lambda to execute business logic;

Push data to WebSocket clients (via API Gateway).

2. Cloud → APP: WebSocket Push Solution

Use API Gateway + WebSocket API + Lambda to implement active cloud push.

Process:

1. APP login (Cognito authorization) establishes WebSocket channel;

2. WebSocket connection is managed by API Gateway;

3. Device reports status/response, IoT rules trigger Lambda;

4. Lambda queries WebSocket connection information and calls @connections interface to push to users.

5. Command issuance (APP → Cloud → Device)

6. APP sends control commands via HTTPS or WebSocket;

7. Backend API (Lambda) decides based on device status:

Online → Publish command to device/{id}/command via IoT Core;

Offline → Store in DynamoDB, wait for device to come online to issue;

8. Device reads commands and processes after coming online.

3. Data Storage Recommendations

IoT Architecture Based on ESP32 and AWS Fully Managed Services: Efficient Device-Cloud-APP Interconnection with MQTT + WebSocket

4. Module Division

ESP32 Firmware Side (Embedded)

MQTT over TLS (connecting to AWS IoT Core)

X.509 certificate management (embedded in flash or OTA issued)

Status reporting, command processing, sleep control

AWS Cloud Module (Serverless)

IoT Architecture Based on ESP32 and AWS Fully Managed Services: Efficient Device-Cloud-APP Interconnection with MQTT + WebSocket

5. Security Design

IoT Architecture Based on ESP32 and AWS Fully Managed Services: Efficient Device-Cloud-APP Interconnection with MQTT + WebSocket

6. Schematic Process: Device Reporting + WebSocket Push

Plain Text [ESP32 Timed Wake] → Connect to AWS IoT Core → Publish to device/xxx/status → IoT Rule triggers Lambda → Lambda pushes to WebSocket (API Gateway) → APP receives real-time device status updates

7. Summary of Advantages

IoT Architecture Based on ESP32 and AWS Fully Managed Services: Efficient Device-Cloud-APP Interconnection with MQTT + WebSocket

Leave a Comment