Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mqttnet 3.1.1 Qos 2 issue #2145

Open
ree-g-dass opened this issue Jan 28, 2025 · 0 comments
Open

mqttnet 3.1.1 Qos 2 issue #2145

ree-g-dass opened this issue Jan 28, 2025 · 0 comments

Comments

@ree-g-dass
Copy link

ree-g-dass commented Jan 28, 2025

An error occurred: Received packet 'PubAck: [PacketIdentifier=1] [ReasonCode=]' at an unexpected time.
I am facing the same issue, only secific to QOS2. Mqttnet 3.1.1, in C#.

var clientOptions = new MqttClientOptionsBuilder()
.WithTcpServer("test",8883) // Broker host and TLS secure post transfer
.WithCredentials("id", "pwd") // Username and password
.WithClientId("id")
.WithTls(new MqttClientOptionsBuilderTlsParameters
{
UseTls = true,
AllowUntrustedCertificates = true, // Set to false in production
IgnoreCertificateChainErrors = true, // Set to false in production
IgnoreCertificateRevocationErrors = true // Set to false in production
})
.WithCleanSession(false) // Clean session false
.WithCommunicationTimeout(TimeSpan.FromSeconds(10000))
.WithKeepAlivePeriod(TimeSpan.FromSeconds(1000))
.WithProtocolVersion(MQTTnet.Formatter.MqttProtocolVersion.V311)
.Build();

Payload: var

mqttMessage = new MqttApplicationMessageBuilder()
.WithTopic("") // Topic
.WithPayload(Encoding.UTF8.GetBytes(serializedMessage)) // JSON Payload
.WithQualityOfServiceLevel(MqttQualityOfServiceLevel.ExactlyOnce) //Qos2 exactly once
.WithRetainFlag()
.Build();

ERROR:

File Read successfully!!
Connecting to MQTT broker...
Connected to MQTT broker.
Connected to MQTT broker successfully.
**An error occurred: Received packet 'PubAck: [PacketIdentifier=1] [ReasonCode=]' at an unexpected time.**
Disconnected from MQTT broker.

The code works fine without await: mqttClient.PublishAsync(mqttMessage); when i use: await mqttClient.PublishAsync(mqttMessage);, it fails with the above error. Do you have any suggestions? @chkr1011 ( is await mandatory for publish?, what could be the potential consequences if i dont use it?)

I tried this based on another issue reference:

var properties = mqttClient.PublishAsync(mqttMessage);
await Task.WhenAll(properties);

Still the same issue. An error occurred: Received packet 'PubAck: [PacketIdentifier=1] [ReasonCode=]' at an unexpected time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant