Skip to content
Advertisement

Connect MQTT Message with clienID of Publisher

I want to store MQTT data in an MySQL db and want to store the client id, topic and message content.

With some devices, I have no control over the topic or message syntax, so it will not be possible to attach the client id to the message or add the client id in the topic.

Is there a possibility to do this?

Maybe a published message can automatically create a topic with the client id?

I saw that mosquitto logs in the server.log the client id without content and in the client log the content without client id … is it possible to link these?

Or maybe there already is a MQTT broker which can do this?

Would be really great if someone could give me some pointers on this.

Advertisement

Answer

Your requirement falls outside of the spec (Client Identifier is not included in messages delivered to subscribers it only “identifies the Client to the Server”). As such I’d be surprised if a broker supported this; however for brokers that allow you hook into the publish flow (e.g. verne) it should be relatively easy to dump the info you want to a database (alternatively if QOS+1 you may be able to hook into the store code).

If you want to pass the info (client ID) on as part of the message then you may want to look into using MQTT v5 for delivery. v5 includes support for properties which provides a way of adding extra data to the message without touching the publish payload.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement