0

Now I can publish message using this

MqttServerClient client = MqttServerClient.withPort(broker, "", 1883); //connect broker

//create message
final builder = MqttClientPayloadBuilder();
builder.addString(message);

client.publishMessage(topic, MqttQos.atLeastOnce, builder.payload); //publish message

but how can I set published message to Retain.

Jedsada
  • 7
  • 3
  • I believe that `client.publishMessage(topic, MqttQos.atLeastOnce, builder.payload, true);` is what you are looking for ([docs](https://pub.dev/documentation/mqtt_client/latest/mqtt_client/MqttClient/publishMessage.html)). – Brits Feb 25 '22 at 23:29

1 Answers1

0

As per the docs the syntax is:

int publishMessage(

    String topic,
    MqttQos qualityOfService,
    Uint8Buffer data,
    {bool retain = false}

) 

So your publish would need to be:

client.publishMessage(topic, MqttQos.atLeastOnce, builder.payload, true);
Brits
  • 14,829
  • 2
  • 18
  • 31