| | |
| | | public static ZbGateway MainGateWay |
| | | { |
| | | get |
| | | { |
| | | return GateWayList.Find((obj) => { return obj.HomeId == Shared.Common.Config.Instance.HomeId && obj.IsMainGateWay; }); |
| | | {
|
| | | ZbGateway mainWay = null; |
| | | for (int i = 0; i < GateWayList.Count; i++)
|
| | | {
|
| | | if (GateWayList[i].HomeId == Config.Instance.HomeId)
|
| | | {
|
| | | //2020.07.16变更:别管那么多,如果住宅ID一样,先确定就是它了(不然有时候经常返回null,有可能是刷新不到)
|
| | | mainWay = GateWayList[i];
|
| | | if (mainWay.IsMainGateWay == true)
|
| | | {
|
| | | //然后如果它确实是主网关,直接break
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | return mainWay; |
| | | } |
| | | } |
| | | |
| | |
| | | /// </summary> |
| | | static Guid currentGuid = Guid.NewGuid(); |
| | | |
| | | public async System.Threading.Tasks.Task SendAesKey()
|
| | | public async Task SendAesKey()
|
| | | {
|
| | | if (PubKey != null)
|
| | | {
|
| | |
| | | } |
| | | } |
| | | |
| | | public async System.Threading.Tasks.Task StartLocalMqtt(string brokerName) |
| | | public async Task StartLocalMqtt(string brokerName) |
| | | {
|
| | | if (localMqttIsConnecting
|
| | | || !Shared.Common.Config.Instance.IsLogin
|
| | | || Shared.Common.Config.Instance.HomeId == ""
|
| | | || localIsConnected)
|
| | | || Shared.Common.Config.Instance.HomeId == ""
|
| | | || localIsConnected)
|
| | | {
|
| | | return;
|
| | | } |
| | |
| | | /// 获取当前帐号所有的网关信息 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | static async System.Threading.Tasks.Task initGateWayBaseInfomation() |
| | | static async Task initGateWayBaseInfomation() |
| | | {
|
| | | if (AllowRemoteCtrl == false)
|
| | | {
|
| | |
| | | public static IMqttClient RemoteMqttClient = new MqttFactory().CreateMqttClient(); |
| | | static bool remoteIsConnected; |
| | | |
| | | /// <summary>
|
| | | /// 远程开始连接的时间点
|
| | | /// </summary> |
| | | private static DateTime RemoteConnectTime = DateTime.Now; |
| | | /// <summary> |
| | | /// 启动远程Mqtt |
| | | /// </summary> |
| | | /// <returns>The start.</returns> |
| | | /// <param name="brokerName">Broker name.</param> |
| | | public static async System.Threading.Tasks.Task StartRemoteMqtt() |
| | | public static async Task StartRemoteMqtt() |
| | | {
|
| | | //追加:没有远程连接的权限
|
| | | if (AllowRemoteCtrl == false
|
| | | || remoteMqttIsConnecting
|
| | | || !Shared.Common.Config.Instance.IsLogin
|
| | | || Shared.Common.Config.Instance.HomeId == ""
|
| | | || remoteIsConnected)
|
| | | {
|
| | | return;
|
| | | } |
| | | await System.Threading.Tasks.Task.Factory.StartNew(async () => |
| | | //如果远程还在连接中 |
| | | if (remoteMqttIsConnecting == true)
|
| | | {
|
| | | //如果这个变量一直处于连接中的状态,但是已经过去了10秒了,还是true的话,说明这里是有点问题的,需要重新创建
|
| | | if ((DateTime.Now - RemoteConnectTime).TotalMilliseconds < 10 * 1000)
|
| | | {
|
| | | return;
|
| | | }
|
| | | } |
| | | //记录起这次远程连接的时间点 |
| | | RemoteConnectTime = DateTime.Now; |
| | | |
| | | await Task.Factory.StartNew(async () => |
| | | { |
| | | try |
| | | { |
| | |
| | | AllowRemoteCtrl = false;
|
| | | return;
|
| | | } |
| | | //虽然不知道对挤下线那一块有没有用,不过先这么弄 |
| | | await System.Threading.Tasks.Task.Delay(1500); |
| | | |
| | | var responseData = jobject["ResponseData"]; |
| | | if (responseData != null) |
| | |
| | | /// <summary> |
| | | /// 断开服务器连接 |
| | | /// </summary> |
| | | public async System.Threading.Tasks.Task DisConnectLocalMqttClient(string s) |
| | | public async Task DisConnectLocalMqttClient(string s) |
| | | { |
| | | try |
| | | { |
| | | if (localIsConnected)
|
| | | {
|
| | | localIsConnected = false;
|
| | | //这个东西也要弄
|
| | | localMqttIsConnecting = false;
|
| | | DebugPrintLog($"Local主动断开_{s}");
|
| | | //await localMqttClient.DisconnectAsync(new MQTTnet.Client.Disconnecting.MqttClientDisconnectOptions { }, CancellationToken.None);
|
| | | await localMqttClient.DisconnectAsync();
|
| | |
| | | /// <summary>
|
| | | /// 断开远程Mqtt的链接
|
| | | /// </summary> |
| | | public static async System.Threading.Tasks.Task DisConnectRemoteMqttClient(string s = "")
|
| | | public static async Task DisConnectRemoteMqttClient(string s = "")
|
| | | {
|
| | | try
|
| | | {
|
| | | if (remoteIsConnected)
|
| | | {
|
| | | remoteIsConnected = false;
|
| | | //这个东西也要弄
|
| | | remoteMqttIsConnecting = false;
|
| | | DebugPrintLog($"Remote主动断开_{s}");
|
| | | //await RemoteMqttClient.DisconnectAsync(new MQTTnet.Client.Disconnecting.MqttClientDisconnectOptions { }, CancellationToken.None);
|
| | | await RemoteMqttClient.DisconnectAsync();
|