Skip to content
IoT

Best Practices for MQTT Telemetry on Low-Power Microcontrollers

30 June 20265 min read1 views
Best Practices for MQTT Telemetry on Low-Power Microcontrollers
Optimize your MQTT payload sizes, Quality of Service (QoS) levels, keep-alive frames, and deep sleep cycles for efficient IoT devices.

Introduction to MQTT in IoT

MQTT (Message Queuing Telemetry Transport) has become the de-facto standard protocol for IoT telemetry. Its lightweight design and publish-subscribe model make it perfect for resource-constrained microcontrollers. However, running MQTT inefficiently can quickly drain batteries and overload brokers. Implementing optimization patterns is essential for production-grade scale.

1. Optimize QoS Levels

MQTT offers three Quality of Service (QoS) tiers:

  • QoS 0 (At most once): Minimal overhead. Messages are sent without confirmation. Use this for highly frequent, non-critical sensor updates (e.g. ambient temperature).
  • QoS 1 (At least once): Demands confirmation handshake. Essential for status updates or alarms where receipt is mandatory.
  • QoS 2 (Exactly once): Highest overhead (4-step handshake). Avoid QoS 2 on low-power devices as it keeps the radio active too long.

2. Keep-Alive Frame Optimization

To detect connection losses, MQTT clients send periodic ping requests (PINGREQ). While active devices benefit from short keep-alive intervals (e.g. 60 seconds), battery-powered nodes should increase this threshold to several hours, or connect, transmit telemetry in a single burst, and disconnect immediately before entering Deep Sleep.

3. Payload Compression

Avoid verbose JSON payloads. Instead of:

{ "device_identification_id": "ESP32-S3-009A", "temperature_celsius": 24.52, "humidity_relative": 58.12 }

Use compact keys or binary serialization formats like Protocol Buffers (Protobuf) or MessagePack:

{ "id": "009A", "t": 24.5, "h": 58.1 }

This small change reduces Wi-Fi radio transmission time and bytes written to network sockets significantly.

Working on an IoT network? Let's talk →

Frequently Asked Questions

Q:Which QoS level is best for low-power sensors?

QoS 0 is ideal because it has no confirmation overhead. If delivery is critical, QoS 1 should be used, but keep transmissions brief.

Q:How do I maintain MQTT state during deep sleep?

MQTT sessions can be persisted using the Clean Session flag set to false, allowing the broker to cache subscriptions while the device sleeps.

Working on something similar?

Let's collaborate to design custom PCB schematics, write deterministic FreeRTOS threads, or configure secure Next.js databases.

Let's talk →
FyraAsk anything