Mqttnet: Doesn't this Client support my own mqtt morker?

Created on 3 Nov 2019  路  4Comments  路  Source: chkr1011/MQTTnet

Describe your question

I user MQTT.fx with username銆乸assword銆乸ort and broker url connect my own mqtt broker锛宔verything works fine.

But when I use this Client with the same infomation, it doesn't work.

Code:
string ServerUrl = "*.iot-as-mqtt.cn-shanghai.aliyuncs.com";
string UserName = "*";
string Password = "
";
string clientId = "
***";
var options = new MqttClientOptionsBuilder()
.WithClientId(clientId)
.WithTcpServer(ServerUrl,1883)
.WithCredentials(UserName, Password)
.WithTls()
.WithCleanSession()
.Build();

        mqttClient.ConnectAsync(options).GetAwaiter().GetResult();

The error info:
MQTTnet.Adapter.MqttConnectingFailedException
HResult=0x80131500
Message=Connecting with MQTT server failed (ClientIdentifierNotValid).
Source=MQTTnet
StackTrace:
at MQTTnet.Client.MqttClient.d__40.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MQTTnet.Client.MqttClient.d__33.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at MQTTnet.Client.MqttClient.d__33.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at ConsoleApp1.Program.Main(String[] args) in C:\Users\Administrator\source\repos\MQTTDemo\ConsoleApp1\Program.cs:line 30

Which project is your question related to?

  • Client

Can you give me some advices, thanks.

question

Most helpful comment

@SeppPenner disregard, after further investigation of the CONNECT packet between MQTT.fx and what was being generated by MQTTnet I noticed the KeepAlive period was the only thing different.

aliyuncs has a requirement that the KeepAlive period is at least 30 seconds. If it's any less it will return an InvalidClient error.

Keep this ticket closed, thank you.

All 4 comments

What is your client id? I mean, the error says: ClientIdentifierNotValid. Maybe something is wrong there or you are using some not supported char maybe?

Another hint might be that you're trying to use SSL on port 1883? I don't know if this is intended, but normally 8883 is the SSL port for MQTT over SSL...

As this issue is open quite long and you didn't answer my question (We need more information to help you out), I will close this issue now. Just write another message here if this still occurs and (if possible provide more information to us).

@SeppPenner I'm having the same issue as the user above, we're both connecting to the same broker it seems.

The clientIds for aliyuncs brokers are a bit long, here's an example:
123456|securemode=3,signmethod=hmacsha1,timestamp=1598679202|

Using the same settings in MQTT.fx it works fine.

@SeppPenner disregard, after further investigation of the CONNECT packet between MQTT.fx and what was being generated by MQTTnet I noticed the KeepAlive period was the only thing different.

aliyuncs has a requirement that the KeepAlive period is at least 30 seconds. If it's any less it will return an InvalidClient error.

Keep this ticket closed, thank you.

Was this page helpful?
0 / 5 - 0 ratings