private void LoggerTimer_Tick(object sender, object e) { if (pinValue == GpioPinValue.High) { pinValue = GpioPinValue.Low; pin.Write(pinValue); ReadWeatherData().ContinueWith((t) => { SensorData sd = t.Result; Kafka kafka = new Kafka(); Debug.WriteLine(sd.Created); //Write the values to your debug console Debug.WriteLine("Created: " + sd.Created + " ft"); time.Text = sd.Created.ToString("g"); Debug.WriteLine("Temperature: " + sd.TemperatureinF + " deg F"); temperature.Text = (sd.TemperatureinF.ToString("F2") + "°F"); Debug.WriteLine("Pressure: " + sd.Pressureinmb + " mb"); pressure.Text = (sd.Pressureinmb.ToString("F0") + " mb"); if (go == true) { Task.Run(() => kafka.PostDataAsync(sd, "SensorData", serverIPURL, serverPort)); //fire and forget for now } }, TaskScheduler.FromCurrentSynchronizationContext()); ReadLightData().ContinueWith((t) => { LightData ld = t.Result; //enable at future date //Kafka kafka = new Kafka(); Debug.WriteLine("Lux: " + ld.Lux); Debug.WriteLine("Color Temp:" + ld.ColorTempinK + " K"); lux.Text = (ld.Lux.ToString("F0") + " lx"); //enable at future date (see above as well) //if (go == true) //{ // Task.Run(() => kafka.PostDataAsync(sd, "SensorData")); //fire and forget for now //} }, TaskScheduler.FromCurrentSynchronizationContext()); pinValue = GpioPinValue.High; pin.Write(pinValue); } else { pinValue = GpioPinValue.High; pin.Write(pinValue); } }
private async Task<LightData> ReadLightData() { LightData ld = null; try { if (colorSensor == null) { colorSensor = new TCS34725(); await colorSensor.Initialize(); } //Read the approximate color from the sensor string colorRead = await colorSensor.getClosestColor(); RgbData rgb = await colorSensor.getRgbData(); float lux = TCS34725.getLuxSimple(rgb); ld = new LightData(); ld.Created = DateTime.Now; ld.rgbData = rgb; ld.Lux = lux; ld.ColorTempinK = TCS34725.calculateColorTemperature(rgb); Debug.WriteLine("Current lux: " + lux); } catch (Exception ex) { Debug.WriteLine(ex.Message); } return ld; }