Ejemplo n.º 1
0
        private void OnTick(object sender, object e)
        {
            var sensor = new RoomSensor()
            {
                Tanggal = DateTime.Now, Gas = gas.ReadProportion(), Humid = temphumid.TakeMeasurement().RelativeHumidity, Light = light.GetReading(), Temp = temphumid.TakeMeasurement().Temperature
            };
            var data = JsonConvert.SerializeObject(sensor);

            client.Publish("mifmasterz/assistant/data", Encoding.UTF8.GetBytes(data), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This is the dispatcher callback.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void GetData(object sender, RoutedEventArgs e)
        {
            if (tempSensor != null & lightSensor != null)
            {
                var temp2 = tempSensor.TakeMeasurement();
                var light = lightSensor.GetReading();

                double temp     = temp2.TemperatureFahrenheit;
                double humidity = temp2.RelativeHumidity;
                Temperature.Text = temp.ToString("F1");
                Humidity.Text    = humidity.ToString("F1");
                Light.Text       = light.ToString("F2");
            }
            else
            {
                rootPage.NotifyUser("Error getting data from sensors", NotifyType.ErrorMessage);
            }
        }