The place where random ideas get written down and lost in time.

2023-02-24 - MQTT

Category DEV

Just leaving this here to explore it later: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/protocols/mqtt.html

 

Guides:

Spec for MQTT v5:

This would be useful for SDB: make it an MQTT client.

But potentially that can be useful for other projects.

For example, my current layout stats from Randall are sent via very hackish REST post (hackish in the sense it’s received via a BASH CGI :-p ⇒ not anymore, it’s a CGI py), and it may be better served by using this protocol: e.g. Conductor sending events to home via broker/gateways, and I'd want to better understand the possibilities.

From the adafruit guide above:

  • An MQTT broker is a “stable” node to which (potentially ephemeral) MQTT clients connect. It’s basically the “local server” of a bunch of clients.
    • Brokers typically have their own local database but they do not have to.
  • An MQTT client is any end-point sending or receiving messages.
    • Publish: A client sends a message to a broker.
    • Subscribe: A client receives messages from a broker.
    • A client keeps an open connection to a broker. The connection open/close is lightweight enough that it can be beneficial to open/close it when needed.
  • MQTT messages have a fairly lightweight header, designed for lightweight payloads.
    • The protocol is mostly transport-agnostic.
    • The spec above recommends TCP, TLS, or WebSockets, and recommends avoiding UDP due to lack of ordering guarantee.
    • QOS: 0=at most once delivery, 1=at least once delivery, 2=exactly once delivery.
  • Messages are sent to “topics”: a hierarchical string e.g. /root/part1/…/partn.
    • Concrete example: /building1/sensors/floor1/division2/temperature.
    • Subscription can be done using wildcards: + for any given part, and # for “anything till the end”.
    • Topics should be carefully defined upfront, as changing the schema later is not trivial especially with regards to wildcard subscriptions.
  • An MQTT gateway is a client/bridge translating data from sensors to MQTT messages (example: sensor ⇔ RF/BLE ⇔ gateway ⇔ MQTT messages ⇔  broker).

MQTT Libraries


 Generated on 2025-01-18 by Rig4j 0.1-Exp-f2c0035