You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
_options = new MqttClientOptionsBuilder()
.WithClientId(ClientID)
.WithTcpServer(Globals.BROKER_ADDRESS, Globals.BROKER_PORT)
.WithCredentials(Globals.BROKER_USER, Globals.BROKER_PASSWORD)
.WithProtocolVersion(MQTTnet.Formatter.MqttProtocolVersion.V500) // Use MQTT version 5.0
.WithTlsOptions(o =>
{
o.UseTls(true);
o.WithAllowUntrustedCertificates(false);
o.WithIgnoreCertificateChainErrors(false);
o.WithIgnoreCertificateRevocationErrors(false);
o.WithCertificateValidationHandler(_ => true);
Assembly assembly = Assembly.GetExecutingAssembly();
byte[]? certPubicKeyData = null;
using (MemoryStream mem = new())
{
assembly.GetManifestResourceStream("MqttClient.Certs.client.key")?.CopyTo(mem);
certPubicKeyData = mem.ToArray();
}
byte[]? certClientData = null;
using (MemoryStream mem = new())
{
assembly.GetManifestResourceStream("MqttClient.Certs.client.crt")?.CopyTo(mem);
certClientData = mem.ToArray();
}
byte[]? certRootData = null;
using (MemoryStream mem = new())
{
assembly.GetManifestResourceStream("MqttClient.Certs.root.crt")?.CopyTo(mem);
certRootData = mem.ToArray();
}
var rootCert = new X509Certificate2(certRootData);
var clientCert = new X509Certificate2(certClientData);
//var clientKey= new X509Certificate2(certPubicKeyData);
o.WithClientCertificates([rootCert, clientCert]);
o.WithSslProtocols(System.Security.Authentication.SslProtocols.Tls12);
})
.WithKeepAlivePeriod(TimeSpan.FromSeconds(60))
.WithWillQualityOfServiceLevel(MqttQualityOfServiceLevel.ExactlyOnce)
.WithCleanStart(true)
.WithSessionExpiryInterval(Globals.BROKER_SESSION_INTERVAL)
.Build();
When I try to connect the Disconnected handler is called with this exception:
**
Error while authenticating. Unexpected Maximum QoS value: 2
**
I tried even with MqttQualityOfServiceLevel.AtLeastOnce but no avail. Always the same error with the same number.
Is there a way to solve this without editing MQTTnet source code??
Digging inside the source code, I have found:
public MqttQualityOfServiceLevel ReadMaximumQoS()
{
var value = _body.ReadByte();
if (value > 1)
{
throw new MqttProtocolViolationException($"Unexpected Maximum QoS value: {value}");
}
return (MqttQualityOfServiceLevel)value;
}
I think this if (value > 1) is wrong. It should be if (value > 2)
Thanks
Jaime
The text was updated successfully, but these errors were encountered:
Responded to OP on stackoverflow (this issue is a copy/paste from there). Server in use is CrystalMQ and this server appears to breach the MQTTV5 spec requirement that Maximum QoS valid values are 0 or 1 only (it sends 2 - verified via wireshark). I believe that MQTTNet is behaving correctly when it rejects this.
Hello.
I have these options to connect to my own broker:
When I try to connect the
Disconnected
handler is called with this exception:**
**
I tried even with
MqttQualityOfServiceLevel.AtLeastOnce
but no avail. Always the same error with the same number.Is there a way to solve this without editing MQTTnet source code??
Digging inside the source code, I have found:
I think this
if (value > 1)
is wrong. It should beif (value > 2)
Thanks
Jaime
The text was updated successfully, but these errors were encountered: