fix:tb不支持qos2可能导致的问题
This commit is contained in:
parent
dd1f802390
commit
2ee5b8c7bd
@ -3,6 +3,7 @@ using IoTGateway.Model;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using MQTTnet;
|
using MQTTnet;
|
||||||
using MQTTnet.Client;
|
using MQTTnet.Client;
|
||||||
|
using MQTTnet.Formatter;
|
||||||
using MQTTnet.Protocol;
|
using MQTTnet.Protocol;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using PluginInterface;
|
using PluginInterface;
|
||||||
@ -50,13 +51,13 @@ namespace Plugin
|
|||||||
#region ClientOptions
|
#region ClientOptions
|
||||||
// Setup and start a managed MQTT client.
|
// Setup and start a managed MQTT client.
|
||||||
_options = new MqttClientOptionsBuilder()
|
_options = new MqttClientOptionsBuilder()
|
||||||
.WithClientId(string.IsNullOrWhiteSpace(_systemConfig.ClientId)
|
.WithClientId(_systemConfig.ClientId ?? Guid.NewGuid().ToString())
|
||||||
? Guid.NewGuid().ToString()
|
|
||||||
: _systemConfig.ClientId)
|
|
||||||
.WithTcpServer(_systemConfig.MqttIp, _systemConfig.MqttPort)
|
.WithTcpServer(_systemConfig.MqttIp, _systemConfig.MqttPort)
|
||||||
.WithCredentials(_systemConfig.MqttUName, _systemConfig.MqttUPwd)
|
.WithCredentials(_systemConfig.MqttUName, _systemConfig.MqttUPwd)
|
||||||
.WithTimeout(TimeSpan.FromSeconds(30))
|
.WithTimeout(TimeSpan.FromSeconds(30))
|
||||||
.WithKeepAlivePeriod(TimeSpan.FromSeconds(20))
|
.WithKeepAlivePeriod(TimeSpan.FromSeconds(60))
|
||||||
|
.WithProtocolVersion(MqttProtocolVersion.V311)
|
||||||
|
.WithCleanSession(true)
|
||||||
.Build();
|
.Build();
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -611,7 +612,7 @@ namespace Plugin
|
|||||||
await Client.PublishAsync(new MqttApplicationMessageBuilder().WithTopic("v1/gateway/connect")
|
await Client.PublishAsync(new MqttApplicationMessageBuilder().WithTopic("v1/gateway/connect")
|
||||||
.WithPayload(JsonConvert.SerializeObject(new Dictionary<string, string>
|
.WithPayload(JsonConvert.SerializeObject(new Dictionary<string, string>
|
||||||
{ { "device", device.DeviceName } }))
|
{ { "device", device.DeviceName } }))
|
||||||
.WithQualityOfServiceLevel(MqttQualityOfServiceLevel.ExactlyOnce).Build());
|
.WithQualityOfServiceLevel(MqttQualityOfServiceLevel.AtMostOnce).Build());
|
||||||
break;
|
break;
|
||||||
case IoTPlatformType.AliCloudIoT:
|
case IoTPlatformType.AliCloudIoT:
|
||||||
break;
|
break;
|
||||||
@ -677,7 +678,7 @@ namespace Plugin
|
|||||||
await Client.PublishAsync(new MqttApplicationMessageBuilder().WithTopic($"v1/gateway/disconnect")
|
await Client.PublishAsync(new MqttApplicationMessageBuilder().WithTopic($"v1/gateway/disconnect")
|
||||||
.WithPayload(JsonConvert.SerializeObject(new Dictionary<string, string>
|
.WithPayload(JsonConvert.SerializeObject(new Dictionary<string, string>
|
||||||
{ { "device", device.DeviceName } }))
|
{ { "device", device.DeviceName } }))
|
||||||
.WithQualityOfServiceLevel(MqttQualityOfServiceLevel.ExactlyOnce).Build());
|
.WithQualityOfServiceLevel(MqttQualityOfServiceLevel.AtMostOnce).Build());
|
||||||
break;
|
break;
|
||||||
case IoTPlatformType.AliCloudIoT:
|
case IoTPlatformType.AliCloudIoT:
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user