From 41f9c8837b0551c68f8fd798c06951fa716b7ab8 Mon Sep 17 00:00:00 2001
From: wei <kaede@kaededeMacBook-Air.local>
Date: 星期一, 11 一月 2021 14:05:29 +0800
Subject: [PATCH] Merge branch 'NewFilePath' of http://172.16.1.23:6688/r/~wxr/HDL_APP_Project into NewFilePath
---
HDL_ON/DAL/Mqtt/MqttClient.cs | 96 +++++++++++++++++++++++++++++++++---------------
1 files changed, 66 insertions(+), 30 deletions(-)
diff --git a/HDL_ON/DAL/Mqtt/MqttClient.cs b/HDL_ON/DAL/Mqtt/MqttClient.cs
index 3161a9f..8b725d6 100644
--- a/HDL_ON/DAL/Mqtt/MqttClient.cs
+++ b/HDL_ON/DAL/Mqtt/MqttClient.cs
@@ -32,18 +32,18 @@
/// </summary>
static string RandomKey = "";
+ /// <summary>
+ /// 闅忔満鐢熸垚瀛楃
+ /// </summary>
+ /// <returns></returns>
static string GetRandomKey()
{
if (string.IsNullOrEmpty(RandomKey))
{
//闅忔満2浣嶅瓧绗︿覆
- Random random = new Random(Guid.NewGuid().GetHashCode());
- int num = random.Next(65, 91);
- RandomKey = Convert.ToChar(num).ToString();
+ RandomKey = Utlis.CreateRandomString(2);
}
-
return RandomKey;
-
}
/// <summary>
@@ -119,7 +119,7 @@
/// <summary>
/// 澶栫綉鐨凪QTT鏄惁姝e湪杩炴帴
/// </summary>
- public static bool remoteMqttIsConnecting;
+ public static bool RemoteMqttIsConnecting;
static bool remoteIsConnected;
static MqttClient()
@@ -132,12 +132,14 @@
static void InitMqtt()
{
new System.Threading.Thread(async () => {
- while (hadGateway)
+ while (true)
{
try
{
System.Threading.Thread.Sleep(500);
if (!Control.Ins.IsRemote) continue;
+ //杩涘叆鍚庡彴涓嶅鐞�
+ if (MainPage.IsEnterBackground) continue;
await StartCloudMqtt();
await SubscribeTopics();
@@ -158,6 +160,10 @@
}
static bool isSubscribeSuccess;
+ /// <summary>
+ /// 璁㈤槄涓婚
+ /// </summary>
+ /// <returns></returns>
static async Task SubscribeTopics()
{
if (remoteIsConnected && !isSubscribeSuccess)
@@ -184,11 +190,17 @@
Topic = $"/user/{MqttInfoConfig.Current.HomeGatewayInfo.gatewayId}/app/thing/property/send",
QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce
};
+ //var topicBusStatus = new MqttTopicFilter()
+ //{
+ // Topic = $"/BusGateWayToClient/{}/Common",
+ // QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce
+ //};
Utlis.WriteLine("寮�濮嬭闃咃紒");
- var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] { topicFilterBusGateWayToClient, topicFilterPush2 , topicAlinkStatus });
+ var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] { topicFilterBusGateWayToClient, topicFilterPush2, topicAlinkStatus });
if (result.Items[0].ResultCode == MQTTnet.Client.Subscribing.MqttClientSubscribeResultCode.GrantedQoS0)
{
+ Control.Ins.GatewayOnline = true;
isSubscribeSuccess = true;
Utlis.WriteLine("璁㈤槄鎴愬姛锛�");
@@ -221,7 +233,7 @@
}
//杩藉姞锛氭病鏈夎繙绋嬭繛鎺ョ殑鏉冮檺
- if (remoteMqttIsConnecting || remoteIsConnected)
+ if (RemoteMqttIsConnecting || remoteIsConnected)
{
return;
}
@@ -232,7 +244,7 @@
try
{
#region 鍒濆鍖栬繙绋婱qtt
- remoteMqttIsConnecting = true;
+ RemoteMqttIsConnecting = true;
RemoteMqttClient = new MqttFactory().CreateMqttClient();
@@ -268,10 +280,10 @@
else
{
SetGatewayOnlineResetCheck();
- var bytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, DB_ResidenceData.residenceData.HomeGateway.aesKey);
+ var bytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, DB_ResidenceData.Instance.HomeGateway.aesKey);
//bus鏁版嵁瑙f瀽
- if (DB_ResidenceData.residenceData.GatewayType == 0)
+ if (DB_ResidenceData.Instance.GatewayType == 0)
{
var packet = new Packet();
@@ -283,13 +295,22 @@
{
packet.Bytes = e.ApplicationMessage.Payload;
}
+#if DEBUG
+ //string ddd = "";
+ //foreach (var bb in packet.Bytes)
+ //{
+ // ddd += bb + ",";
+ //}
+ //MainPage.Log($"mqtt bus data:{ddd}");
+#endif
packet.Manager();
}
else
{
+ MainPage.Log($"mqtt A-Link data");
//A鍗忚鏁版嵁澶勭悊
var revString = Encoding.UTF8.GetString(bytes);
- Control.Ins.UpdataFunctionStatus(revString);
+ Control.Ins.UpdataFunctionStatus(revString,null);
}
}
}
@@ -309,12 +330,11 @@
//(3)ConnectedHandler
if (RemoteMqttClient.ConnectedHandler == null)
{
- RemoteMqttClient.UseConnectedHandler(async (e) => {
- Control.Ins.GatewayOnline = true;
+ RemoteMqttClient.UseConnectedHandler(async (e) =>
+ {
IfNeedReadAllDeviceStatus = true;
Utlis.WriteLine($"============>Mqtt杩滅▼杩炴帴鎴愬姛");
SendPushSignOut();
- FunctionList.List.ReadAllFunctionStatus();
});
}
#endregion
@@ -341,7 +361,7 @@
finally
{
//鏈�缁堣閲婃斁杩炴帴鐘舵��
- remoteMqttIsConnecting = false;
+ RemoteMqttIsConnecting = false;
Utlis.WriteLine($"StartCloudMqtt: 缁撴潫");
}
@@ -371,7 +391,7 @@
{
try
{
- if (MqttInfoConfig.Current.HomeGatewayInfo != null && MqttInfoConfig.Current.HomeGatewayInfo.mac == Entity.DB_ResidenceData.residenceData.residenceGatewayMAC)
+ if (MqttInfoConfig.Current.HomeGatewayInfo != null && MqttInfoConfig.Current.HomeGatewayInfo.mac == Entity.DB_ResidenceData.Instance.residenceGatewayMAC)
{
await MQTTConnectAsync();
}
@@ -524,7 +544,9 @@
/// </summary>
static void ReceiveNotifySqueezeAsync(string mMes)
{
-
+//#if DEBUG
+ return;
+//#endif
if (mMes == PushSignStr) return;//鏄嚜宸辩殑鐧诲綍鎺ㄩ�佷笉澶勭悊
//鏂紑杩滅▼杩炴帴
@@ -536,13 +558,20 @@
DisConnectRemoteMqttClient("鎸や笅绾�");
- UserInfo.Current.LastTime = DateTime.MinValue;
- UserInfo.Current.SaveUserInfo();
-
- Application.RunOnMainThread(() => {
- MainPage.GoLoginPage(UserInfo.Current);
+ Application.RunOnMainThread(() =>
+ {
//寮圭獥鎻愮ず琚尋涓嬬嚎
+ HDLCommon.Current.CheckLogout();
});
+
+
+ //UserInfo.Current.LastTime = DateTime.MinValue;
+ //UserInfo.Current.SaveUserInfo();
+
+ //Application.RunOnMainThread(() => {
+ // MainPage.GoLoginPage(UserInfo.Current);
+ // //寮圭獥鎻愮ず琚尋涓嬬嚎
+ //});
//2020-08-11 鍒犻櫎鎺ㄩ�佹暟鎹�
//HDLRequest.Current.PushserivceSignOut ();
@@ -580,8 +609,6 @@
/// <returns></returns>
public static async Task MqttRemoteSend(byte[] message, int optionType = 0)
{
- //return;
-
try
{
string topicName;
@@ -627,7 +654,6 @@
/// 鏄惁闇�瑕佽鍙栦竴娆℃墍鏈夎澶囩姸鎬�
/// </summary>
static bool IfNeedReadAllDeviceStatus = true;
- //public static bool IsGatewayOnline = true;
/// <summary>
/// 璁剧疆缃戝叧鍦ㄧ嚎鏍囧織锛屽苟閲嶇疆CheckGateway鍙傛暟
@@ -637,7 +663,17 @@
if (Control.Ins.IsRemote)
{
if (!Control.Ins.GatewayOnline)
- Control.Ins.GatewayOnline = true;
+ {
+ try
+ {
+ if (DB_ResidenceData.Instance.HomeGateway != null)
+ {
+ DB_ResidenceData.Instance.HomeGateway.gatewayStatus = true;
+ }
+ Control.Ins.GatewayOnline = true;
+ }
+ catch { }
+ }
}
}
@@ -654,10 +690,10 @@
MqttInfoConfig.Current.mMqttInfo = mqttInfoRequestResult_Obj;
await MQTTConnectAsync();
//1.鍒ゆ柇鏄惁缁戝畾浜嗙綉鍏筹紝鑾峰彇缃戝叧杩滅▼杩炴帴鐨勫姞瀵咾EY
- if (DB_ResidenceData.residenceData.CheckWhetherGatewayIsBound())
+ if (DB_ResidenceData.Instance.CheckWhetherGatewayIsBound())
{
//2.鎵惧嚭鏄惁瀛樺湪鍖归厤褰撳墠浣忓畢鐨刴ac锛屽瓨鍦ㄥ啀杩涜杩滅▼銆�
- MqttInfoConfig.Current.HomeGatewayInfo = DB_ResidenceData.residenceData.HomeGateway;
+ MqttInfoConfig.Current.HomeGatewayInfo = DB_ResidenceData.Instance.HomeGateway;
//3.寮�濮嬭繛鎺�
await MQTTConnectAsync();
}
--
Gitblit v1.8.0