0

I'm using Mosquitto MQTT broker in my embedded Linux device. The current topology is like below:

MQTT clients(Publishers) -------MQTT broker--------MQTT clients(Subscribers)

To get the data from MQTT broker which data are published by client, shall I create MQTT clients(Subscribers) in my embedded Linux device?

Is there any way to make a simple application in c or c++ to get the data from MQTT broker which data were published by clients(publisher) so that CPU time and memory than creating MQTT client(sub)? Please let me know how. Thank you. //Daum

Happy
  • 133
  • 8
  • It's really not clear what you are asking here, but there is no way to know which client published a given message, unless you add that information to the payload or use a topic per publisher. – hardillb Sep 20 '18 at 08:05
  • Sorry if my question wasn't that clear. I just want make an application that hooks the broker to get the information which clients published. – Happy Sep 20 '18 at 09:15
  • I'm assuming that the information of published message includes source client ID, Topic, maybe published client IP address, and/or the information in the payload. – Happy Sep 20 '18 at 09:19
  • No, messages just contain topic and payload, nothing else – hardillb Sep 20 '18 at 09:25

1 Answers1

0

MQTT v3.1 messages only contain the following information:

  1. Topic
  2. QOS level
  3. Retained flag
  4. Payload

There is no information about who published the message, if you need that information you will need to find a way to encode it in the payload when you publish it or use client specific topics.

hardillb
  • 54,545
  • 11
  • 67
  • 105
  • Sure, but within the payload is the data. So how to get that data out of the payload? – Owl Jun 09 '22 at 13:35
  • 1
    @Owl The payload only contains what data you put in it, so it is entirely up to you to work out how to encode the sender information and how to then extract it when it is received. – hardillb Jun 09 '22 at 13:48
  • You're absolutely right, thanks. – Owl Jun 09 '22 at 18:56