How to determine the MQTT client ID?

I currently have an MQTT system where one client publishes and one subscribes. Now I want a system in which many clients publish. The suspect must understand which client sends the information.

While one obvious way to do this is to simply add the client ID to the post message, I wanted to know if there is a way to get the client ID without explicitly adding it to the message.

To develop, suppose the topic is "/ hello / world" and client 1 publishes "OK", client 2 publishes "ERR". Is there any way to determine which client sent which message?

+4
source share
2 answers

, , , .

, , ; (client_id )

/hello/clientid1/world ok /hello/clientid2/world err /hello/clientid3/world warning

; /hello/+/world , .

, , json ,

/hello/world {"msg":"err", "client":"clientid1"}

+7

, . , , - , - , .

, , - .

+9

All Articles