How to set up an MQTT bridge to retain last messages?

Hello all,
I like bridge the ttn mqqt broker with my, and all is ok, but I need add the retain bit on message.
Actually the ttn broker don’t set it, and with my mosquitto broker I cannot add the retain with bridged message.
There is a way to add the retain bit in ttn mqtt pubblication?
Thanks.

Alberto

So you are expecting TTN to retain the last message for you? If so, then I don’t think that’s related to bridging anything?

If you’re expecting your own broker to do that, then I’m quite sure it should be possible, but then it’s not specific for TTN. Maybe people can help you if you explain more about the setup of your own MQTT broker.

Thanks,
I’ve my mosquitto broker, I need retained messages.
My solution was bridge ttn mqqt broker with mine, sobscribing on my app messages, and add the retention on my mqtt server.
But I think this is not possible in broker config.
The other solution was a one message subsciption, wit a wile true loop in bash, wit pub sub commands, but this is my last choose.

I very much doubt TTN is going to take care of this.

(I think it would imply their MQTT broker needs to retain the last message for all nodes, for there is no way to otherwise indicate which application wants retained messages. And how long would they need to retain them? Not the responsibility of TTN, I’d say.)

1 Like

MQTT doesn’t save messages far as I know. Try adding node red to the mix, you can get the MQTT messages in and re-route them to a local database, text file, or online service. you can make your dashboard in node red to display the values as well. I have all these running on the Pi along side the ttn stuff it was pretty straight forward to install. good luck

1 Like

Peeking into some Google results, I think you’re right…

Node-RED would support this; Publish a retained message to a topic : Node-RED Feels like an overkill to run Node-RED just for this, but it might also be useful for any other processing you might want to do, or if you want to publish differently, like by using web sockets.

Yes, it can. But the message (not the broker) needs to define if it wants to be saved as the last known good message, and apparently TTN is not setting that. I’d assume that while bridging one could also rewrite that retain bit, but apparently not (at least not when using Mosquitto).

Yes, I just try remove the nodered layer from the project…

You can try to use persistent session: persistent clients (those with clean session set to false)

https://www.hivemq.com/blog/mqtt-essentials-part-7-persistent-session-queuing-messages

should be supported by mosquitto.

Persistent clients are unrelated to retained messages.

Once all known persistent clients have retrieved and confirmed all messages they subscribed to, the server can/should delete the messages it saved. Retained messages are meant for new clients that want some defined start state.