Hi Pakaj,
like Andy reported, if you are the MQTT client and want to discover the MQTT broker in the same network, the only way is to use additional libraries which are able to broadcast messages from broker to clients with the information for the connection (Avahi or UPnP are two examples).
If instead you are already connected to an MQTT Broker (maybe hard coded) and want to discover the other devices, you could use a common topic and send an heartbeat to it from all the devices.
For example:
- Device A connect to broker and subscribe to topic "ANNOUNCE".
- Device A start to send every 10 secs a message to the topic "ANNOUNCE" with the information about itself (ip address, uuid, topic on which it post data)
- Device B connect to broker and subscribe to topic "ANNOUNCE". Will start to be notified by the messages sent by Device A
- Device B start to send every 10 secs a message to the topic "ANNOUNCE" with the information about itself
The main idea is to share a topic between devices to allow them to exchange heartbeat messages.