增加云平台mqtt版本配置项

master
rszn 6 months ago
parent 5c58db7ac3
commit 3965906566

@ -210,6 +210,7 @@ public class StationParamConst
#region cloud param #region cloud param
public static readonly string CloudServerMqttVersion = "Cloud.CloudServerMqttVersion";
public static readonly string CloudServerIp = "Cloud.CloudServerIp"; public static readonly string CloudServerIp = "Cloud.CloudServerIp";
public static readonly string CloudServerPort = "Cloud.CloudServerPort"; public static readonly string CloudServerPort = "Cloud.CloudServerPort";
public static readonly string CloudClientId = "Cloud.CloudClientId"; public static readonly string CloudClientId = "Cloud.CloudClientId";

@ -43,7 +43,7 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR
public string? Password { get; set; } public string? Password { get; set; }
public int KeepalivePeriod { get; set; } = 3000; public int KeepalivePeriod { get; set; } = 3000;
public int Timeout { get; set; } = 60; public int Timeout { get; set; } = 60;
public string Version { get; set; } = "5.0.16"; public string MqttVersion { get; set; } = "4.0.0";
public bool IsCleanSession { get; set; } = false; public bool IsCleanSession { get; set; } = false;
#endregion #endregion
@ -225,7 +225,7 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR
MqttTopicFilter topicFilter = new MqttTopicFilter MqttTopicFilter topicFilter = new MqttTopicFilter
{ {
Topic = str, Topic = str,
QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce QualityOfServiceLevel = MqttQualityOfServiceLevel.AtLeastOnce
}; };
list.Add(topicFilter); list.Add(topicFilter);
} }
@ -366,7 +366,7 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR
builder.WithKeepAlivePeriod(TimeSpan.FromSeconds(KeepalivePeriod)) builder.WithKeepAlivePeriod(TimeSpan.FromSeconds(KeepalivePeriod))
.WithCommunicationTimeout(TimeSpan.FromSeconds(Timeout)); .WithCommunicationTimeout(TimeSpan.FromSeconds(Timeout));
switch (Version) switch (MqttVersion)
{ {
case "3.1.0": case "3.1.0":
builder.WithProtocolVersion(MqttProtocolVersion.V310); builder.WithProtocolVersion(MqttProtocolVersion.V310);

@ -1,13 +1,9 @@
using Autofac; using Autofac;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Redis; using HybirdFrameworkCore.Redis;
using log4net; using log4net;
using Newtonsoft.Json;
using Repository.Station; using Repository.Station;
using Service.Cloud.Msg;
using Service.Cloud.Msg.Host.Req;
using Service.Init; using Service.Init;
namespace Service.Cloud.Client; namespace Service.Cloud.Client;
@ -22,6 +18,7 @@ public class CloudClientMgr
{ {
CloudClient = AppInfo.Container.Resolve<CloudClient>(); CloudClient = AppInfo.Container.Resolve<CloudClient>();
CloudClient.MqttVersion = StaticStationInfo.CloudServerMqttVersion;
CloudClient.ServerIp = StaticStationInfo.CloudServerIp; CloudClient.ServerIp = StaticStationInfo.CloudServerIp;
CloudClient.ServerPort = StaticStationInfo.CloudServerPort; CloudClient.ServerPort = StaticStationInfo.CloudServerPort;
CloudClient.ClientId = StaticStationInfo.CloudClientId; CloudClient.ClientId = StaticStationInfo.CloudClientId;

@ -1,7 +1,6 @@
using Autofac; using Autofac;
using Entity.Constant; using Entity.Constant;
using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac;
using Service.Station;
using Service.System; using Service.System;
namespace Service.Init; namespace Service.Init;
@ -135,17 +134,17 @@ public class StaticStationInfo
{ {
get get
{ {
string port = Resolve(StationParamConst.CloudServerPort); string port = Resolve(StationParamConst.CloudServerPort, "33000");
if (string.IsNullOrWhiteSpace(port))
{
return 33000;
}
return int.Parse(port); return int.Parse(port);
} }
set => Set(StationParamConst.CloudServerPort, value); set => Set(StationParamConst.CloudServerPort, value);
} }
public static string CloudServerMqttVersion
{
get => Resolve(StationParamConst.CloudServerMqttVersion, "4.0.0");
set => Set(StationParamConst.CloudServerMqttVersion, value);
}
public static string CloudClientId public static string CloudClientId
{ {
get => Resolve(StationParamConst.CloudClientId); get => Resolve(StationParamConst.CloudClientId);
@ -182,7 +181,7 @@ public class StaticStationInfo
private static SysConfigService _sysConfigService; private static SysConfigService _sysConfigService;
private static string Resolve(string key) private static string Resolve(string key, string? value = default)
{ {
if (_sysConfigService == null) if (_sysConfigService == null)
{ {
@ -195,7 +194,7 @@ public class StaticStationInfo
return s; return s;
} }
return ""; return value;
} }
private static void Set(string key, object value) private static void Set(string key, object value)

Loading…
Cancel
Save