/// <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); } }
private void _server_ActuatorValue(object sender, ActuatorData e) { if (e.Asset == "4") { if ((bool)e.Value == true) { Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { RedLed.Fill = redBrush; redLed.ChangeState(GrovePi.Sensors.SensorStatus.On); }); _device.Send(4, "true"); //feedback for led } else { Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { RedLed.Fill = grayBrush; redLed.ChangeState(GrovePi.Sensors.SensorStatus.Off); }); _device.Send(4, "false"); } } }
static void _device_ActuatorValue(object sender, ActuatorData e) { _logger.Trace("incomming value found: {0}", e.ToString()); //check the actuator for which we received a command //the actuator id always comes in as a string. if (e.Asset == "1") { //actuators can send simple strings or complex json values. //do something with the value if ((bool)e.Value == true) { _logger.Trace("actuating sensor"); } } }