The publisher has to specify the retain flag, not the subscriber.
What is publishing the required door status?
That's where the retain is needed and then when your subscriber starts up again, it will get the current status sent as soon as it subscribes.
Nope. You're missing the point. You have something that sends a message to the broker saying door open or door closed. What is that thing?
client.publish(switchStatus, "1",true); // publish on MQTT the dor UP / client.publish(topic, payload, retained)
Your nodeMCU is subscribing to the topic that contains the open or close messages. There is nothing the subscriber can do to require that it receives the last message sent. Only the publisher can set that up for you.If the publisher has done its job, the nodeMCU just needs to subscribe as it does today and the last message will be automagically sent to it.
mqtt:publish(topic, payload, qos, retain[, function(client)])
connected with DaVinci17Mesh, channel 6dhcp client start...ip:192.168.1.152,mask:255.255.255.0,gw:192.168.1.1.WiFi connectedIP address: 192.168.1.152Attempting MQTT connection... MQTT ConnectedMQTT Callback Topic: pollaio/switchCMD/ <<< here is the first callback routine at the connectionMQTT Callback Payload = 1 (go UP) <<< here arrive the retained message cause the last msg was "1"MQTT ACTUAL doorSwitch = DOWN <<< the default variable at power on is DOWN MQTT > door go UP motorUP INIT...motorUP FINISH...motorUP FINISH ACTUAL doorSwitch = UPWebServer ON...Sabato, 9:26:58 L O O P > doorSwitch = UP