/// <summary> /// Handles the MqttMsgPublishReceived event of the client control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="MqttMsgPublishEventArgs"/> instance containing the event data.</param> void client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e) { try { string[] parts = e.Topic.Split(new char[] { '/' }); TopicPath path = new TopicPath(parts); string mode = path.Mode.ToLower(); if (mode == "command" && path.AssetId != null) //it can only be an actuator value is there is an asset path. { OnActuatorValue(path, e); } else if (_logger != null) { _logger.Error("invalid mode: " + mode + ", can't dispatch message"); } } catch (Exception ex) { if (_logger != null) { _logger.Error("problem with incomming mqtt message", ex.ToString()); } } }
/// <summary> /// Called when a value arrived that has to be sent to an actuator /// </summary> /// <param name="path">The path.</param> /// <param name="e">The <see cref="MqttMsgPublishEventArgs"/> instance containing the event data.</param> private void OnActuatorValue(TopicPath path, MqttMsgPublishEventArgs e) { if (ActuatorValue != null) { #if WINDOWS_UAP string val = System.Text.Encoding.UTF8.GetString(e.Message, 0, e.Message.Length); #else string val = System.Text.Encoding.UTF8.GetString(e.Message); #endif ActuatorData data = new ActuatorData(); data.Load(val); data.Asset = path.AssetId; ActuatorValue(this, data); } }