Exemplo n.º 1
0
        private void Client_MqttMsgPublishReceived(object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e)
        {
            try
            {
                switch (e.Topic)
                {
                case MqttTopic.RegisterTopic:
                    SmartLockRegister smartLock = new SmartLockRegister(e.Message);
                    byte[]            resArray  = smartLock.PackageResponse();
                    MqttClient        client    = (MqttClient)sender;
                    string            resTopic  = MqttTopic.GetClientTopic("SYS", smartLock.SmartLockClient.IotID, "REG");
                    client.Publish(resTopic, resArray);
                    break;

                case MqttTopic.EventTopic:
                    SmartLockDataPackage dataPackage = new SmartLockDataPackage(e.Message);
                    break;

                case MqttTopic.RespondTopic:
                    break;

                case MqttTopic.DataTopic:
                    break;
                }
            }
            catch (Exception ex)
            {
                MqttErroEventArgs eventArgs = new MqttErroEventArgs((sender as MqttClient).ClientId, ex.Message);
                RaiseMqttErroOccurred(eventArgs);
            }
        }
Exemplo n.º 2
0
 private void RaiseMqttErroOccurred(MqttErroEventArgs eventArgs)
 {
     MqttErroOccurred?.Invoke(this, new MqttErroEventArgs(eventArgs.ErroID, eventArgs.ErroString));
 }