MQTT - subscribe retained messages

Hello,

I have following issu.
I have a device, which is normaly in deep sleep and wakes up every 30 minutes to send some sensor readings and also to check for a retained mqtt message. this mqtt message is send by another device using the retained flag. so, as soon as you connect to the mqtt broker with any client and have subscribed that topic, you get imediately the latest mqtt message from that device.
the problem is, I just have a mqtt sketch, where I am using the standard mqtt callback function. this only works when a mqtt message is send just in the moment the device is turned on. The callback function does not get the retained messages from the broker.
so, is there an example, how you can get retained messages from the broker?

thanks a lot

That's odd, I would not expect your script to have to do anything different to get the retained message.

Can you prove to yourself that the retained message is published using a terminal based client on a PC?

it is published. as soon as i connect to the broker with MQTTBox, I receive the latest (retained) message.

Update: I found the solution. I have to delay the check for the status a little bit. the loop ran too fast so the tobic was received too late did not appear in time.

thank you for your help!