The place where random ideas get written down and lost in time.
2021-02-17 - ESP32 Learning: MQTT
Category DEVThis is something I need to look into at some point: MQTT to send messages between ESP32 nodes on a local network.
There’s a group (MQTT4MR) that uses that to control sensors via JMRI (instead of C/MRI over RS485 wires).
MQTT is also used typically with LoRa and such for larger distance networks, I believe using brokers/hubs. However that’s not really my first usage.
https://learn.adafruit.com/mqtt-adafruit-io-and-you?view=all MQTT very high overview:
- Designed for sensors … small payloads, infrequent data, not heavy streams.
- Which is why it works well with LoRa (bandwidth vs distance, pick one).
- It’s a N-to-1 design: one server somewhere, multiple clients.
- Either one device acts as a server, or a “broker” app/script runs on a network computer.
- JMRI uses the latter design for obvious reasons.
- There are internet-wide brokers like adafruit.io
- To connect to a broker, need server/ip, port, username, and a key.
- The whole concept is a pub-sub:
- Devices publish to the server.
- Devices subscribe to the server.
- Subscribers need to send a ping (e.g. every 5 minutes).
- Failing to ping disconnects the device.
- Adafruit_MQTT is such a lib for arduino.
- They warn it’s single-duplex: a subscription message would be lost if the device is transmitting (ping or publication) at the same time.
- Quality-of-service:
- QOS 0 = send publication message without checking they arrived.
- QOS 1 = send publication message with an OK / ack.
- A “will” is a message defined such that the broker sends it when the client disconnects.
Generated on 2025-02-20 by Rig4j 0.1-Exp-f2c0035