Reach a server

MQTT TCP telemetry

The usual channel for sensors and remote commands.

Reach a server MQTT ESP32 Wi-Fi parts

Official path: examples/protocols/mqtt/tcp

01 Overview

Connect, subscribe, publish.

  • Use when: telemetry, remote switches.
  • Skip when: LAN page only, or BLE only.
  • The TCP example is plaintext. Use the SSL example on the public internet.

02 Hardware

  • Wi-Fi must already work. MQTT needs no extra pins.
  • Battery products should not sit on TCP all day — combine with sleep.

03 Software flow

1. Wait for GOT_IP.

2. Configure broker and client ID.

3. Subscribe and publish on CONNECTED.

4. Parse payloads on DATA; the official code only logs.

5. Unique client IDs and topics per device.

04 Core points

  • Stable IP before MQTT.
  • Plain MQTT is not a public-internet product.
  • Custom work: broker, TLS, report period.

中文

连上服务器

MQTT TCP 上报

传感上报和远程命令最常见的通道。

连上服务器 MQTT ESP32 Wi-Fi parts

官方路径: examples/protocols/mqtt/tcp

01 项目概述

连接 MQTT 代理,订阅/发布。

  • 适用: 遥测、远程开关。
  • 不适用: 仅局域网网页;仅 BLE。
  • 官方 TCP 示例默认明文。 公网应改 SSL 示例。

02 项目硬件描述

  • 先能 Wi-Fi。MQTT 不占专用脚。
  • 电池产品不要 24 小时挂 TCP,要和深睡一起设计。

03 项目软件流程描述

1. 等 GOT_IP。

2. 配 broker、Client ID,注册事件。

3. CONNECTED 后订阅并发布。

4. DATA 里解析业务;官方只打印。

5. 量产 Client ID 和主题必须按设备唯一。

04 项目核心点

  • 先稳 IP,再开 MQTT。
  • 明文不能出公网。
  • 可定制: 云平台、TLS、省电上报周期。