The greenhouse has two sensor nodes, a fan controller, a phone dashboard and a logger in the cloud. Without a broker, a sensor has to know the address of every device that wants its readings, and send each of them a copy: every new display means reprogramming the sensor. MQTT puts a broker in the middle (here Mosquitto, running on a Raspberry Pi). Every device makes one connection to it. A sensor publishes each reading once, to a topic such as greenhouse/1/temp; the broker sends a copy to every client that has subscribed to that topic. Publishers and subscribers never know about each other. Switch between the two designs and add subscribers.
Challenge: With the broker, add three new subscribers and get a reading to all of them without touching node 1.
PUBLISHacknowledgementsconnect and subscribekeep-alive pingsa will✕ lostRretained copy· each hop is slowed to 450 ms
← Start here
Speedt = 0.0 s
Design
Subscribers
Node 1 sends per reading
1
Last reading reached
0 of 2
Node 1 must know
the broker only
With a broker, node 1 sends one PUBLISH whatever the number of subscribers, and a new subscriber only has to connect and SUBSCRIBE. All the clients connect out to the broker, so none of them needs to be reachable from outside.