跳到主要内容
uencoder

Use MQTT topic 结构为 IoT messaging

MQTT topics use slash-separated hierarchies 具有 wildcards 为 subscription. Learn topic 设计, QoS 级别, 和 retained messages.

  1. 1

    MQTT topics 是 slash-separated hierarchical paths: home/livingroom/temperature. 它们是 情况-sensitive 和必须不 启动或 结束具有 /. Wildcards: + matches one 级别 (home/+/temperature), # matches 所有 remaining 级别 (home/# — 必须是 最后). Subscribers use wildcards; publishers 总是发布到 特定 topic.

  2. 2
    URL 解析器 →

    解析 an MQTT topic like a URL path to understand its hierarchy. Split on / to get the topic levels. This helps validate topic structure and design hierarchical naming schemes for IoT devices.

  3. 3
    URL 编码器 →

    编码 special characters in MQTT topics. Topics can contain spaces and UTF-8 characters, but they should be URL-encoded for safety. Avoid leading spaces, which are valid but confusing. Use lowercase with hyphens for consistency.

常见问题

什么是 MQTT QoS 级别?
QoS 0: 在最多一次 (fire 和忘记, 否 acknowledgment). QoS 1: 在最少一次 (acknowledged, 可以重复). QoS 2: exactly 一次 (four-步骤 handshake, 否重复). Use QoS 0 为 frequent sensor 数据 (重复 don't matter), QoS 1 为 commands, QoS 2 为关键 messages (billing, 声明 changes).
什么是 retained 消息?
retained 消息是 最后消息 published 到 topic, stored 通过 broker. 新 subscribers immediately 接收 retained 消息开 subscription. 此是 useful 为声明 (device 开/关, 当前 temperature) — 新 clients get 当前声明无 waiting 为下一个发布. Only one retained 消息 per topic.

解决此任务的工作流

相关工具