| | |
| | | /// </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> |
| | |
| | | static void InitMqtt() |
| | | { |
| | | new System.Threading.Thread(async () => { |
| | | while (hadGateway) |
| | | while (true) |
| | | { |
| | | try |
| | | { |
| | |
| | | Topic = $"/user/{MqttInfoConfig.Current.HomeGatewayInfo.gatewayId}/app/thing/property/send", |
| | | QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce |
| | | }; |
| | | var topicBusStatus = new MqttTopicFilter() |
| | | { |
| | | Topic = $"/BusGateWayToClient/MacMask/Common", |
| | | 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, topicBusStatus }); |
| | | var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] { topicFilterBusGateWayToClient, topicFilterPush2, topicAlinkStatus }); |
| | | if (result.Items[0].ResultCode == MQTTnet.Client.Subscribing.MqttClientSubscribeResultCode.GrantedQoS0) |
| | | { |
| | | isSubscribeSuccess = true; |