mqttiotsubscribebroker

MQTT multiple subscribers to one topic


I've recently started using the MQTT broker in AWS, where one device receives messages to control a wind turbine. Now, I wanted to expand this control by connecting a second device to the broker topic. However, I've noticed that when two devices are connected, they seem to constantly 'fight' for connection, pushing each other off. I thought MQTT could support multiple subscribers? When I turn off one of the devices, everything works as expected.


Solution

  • MQTT clients must each have a unique Client ID. The MQTT spec says that if a second client connects with the same client id the broker MUST disconnect the first.

    Clients can share the same username/password, but they can not share client ids.

    Most MQTT client libraries will generate random client ids if none are set.