The device sits behind a home router with no port forward and no public address, and it still has to receive configuration within seconds. The trick is not a hole in the firewall. It is a connection the device opens outward to a broker it can reach, which then hands messages back down that same established path. Every property people like about this design, and every trap in it, comes from that inversion.

What actually gets through the NAT

When the device opens a TCP connection to the broker, the home router creates a mapping and keeps it alive for the life of the flow. Replies on that flow return to the device because the mapping already exists. The broker never initiates anything toward the house, so there is no unsolicited inbound packet for the router to reject. That is the entire networking argument, and it is why the approach works on networks you do not control.

The device must keep the connection alive or re-establish it, which becomes the reliability question once the architecture is settled.

The broker routes topics, it does not proxy HTTP

MQTT defines publish and subscribe exchanges: the device subscribes to a topic filter it is permitted to read, and an authorized controller publishes to a matching topic. The broker matches publications against subscriptions and delivers copies. It does not know what a browser request is, and it will not forward an HTTP GET to the device's web server. If the existing firmware only speaks HTTP, the broker design needs an application change or a deliberate translation component.

Topic names are also not authorization. Most brokers support per-client access control lists, and devices should be restricted to their own publish and subscribe trees rather than sharing one global namespace.

Device resources decide the TLS shape

An ESP8266 has limited RAM, and a TLS handshake is the most expensive thing it does. The Arduino core ships BearSSL specifically for this constraint, and the choice between verifying a CA and pinning a fingerprint changes both the memory footprint and what an attacker with a valid certificate for another name can do. Verifying the broker's CA is the stronger option when the heap allows it. Payload size matters as well: the MQTT client holds a buffer, and messages larger than it are silently truncated unless the buffer is raised deliberately.

Keepalive and socket timeouts are part of the same budget, because a client that never notices a dead connection stops receiving commands without reporting an error.

The message semantics that bite

A retained message is stored by the broker and delivered to later matching subscribers, which is excellent for current state and dangerous for one-time commands: a device that reconnects can receive yesterday's command as if it were new. QoS 1 guarantees at-least-once delivery, so duplicates are normal and the application has to be repeat-safe, ideally with an identifier or a timestamp it can reject. The last will and testament gives you a status signal when the device drops, but only if the connection actually fails rather than hanging.

Clean session behaviour decides whether the broker keeps your subscriptions while you are away, and getting that wrong is why some devices miss the first message after every reconnect.

TLS protects the hop to the broker. It is not end-to-end payload encryption against the broker operator, who can read everything you publish through it.

Bound the lifecycle and test it with harmless data

Plan reconnection with backoff rather than a tight retry loop, resubscribe explicitly if the session is not persistent, and log the connect result so a silent offline device leaves evidence. Test the reconnect path with sample payloads that do nothing, because the first production test of a command channel should not be a real command. Then confirm what a stale retained message does on reconnect, and decide whether that behaviour is acceptable for each topic.

Done this way, the design removes one inbound network requirement and leaves the device software, the broker policy and the message semantics as visible work rather than hidden assumptions.

Nuŋlɔɖi siwo ku ɖe eŋu