/// <summary> /// Samples each of the sensors and stores the values in <see cref="sampleBuffer"/>. /// </summary> /// <param name="time"> /// The current time, in UTC. /// </param> private void Sample(DateTime time) { List <Thread> threads = new List <Thread>(); threads.Add(new Thread(() => { if (config.IsSensorEnabled(AwsSensor.AirTemperature)) { try { sampleBuffer.AirTemperature.Add(airTempSensor.Sample()); } catch { gpio.Write(config.errorLedPin, PinValue.High); } } if (config.IsSensorEnabled(AwsSensor.RelativeHumidity)) { try { sampleBuffer.RelativeHumidity.Add(relHumSensor.Sample()); } catch { gpio.Write(config.errorLedPin, PinValue.High); } } if (config.IsSensorEnabled(AwsSensor.StationPressure)) { try { sampleBuffer.StationPressure.Add(staPresSensor.Sample()); } catch { gpio.Write(config.errorLedPin, PinValue.High); } } })); threads.Add(new Thread(() => { if (config.IsSensorEnabled(AwsSensor.Satellite)) { try { SatelliteSample sample = satellite.Sample(); if (sample.WindSpeed != null) { if (lastWindSpeedSampleTime != null && lastWindSpeedSampleTime == time - TimeSpan.FromSeconds(1)) { sampleBuffer.WindSpeed.Add(new KeyValuePair <DateTime, double>(time, ((int)sample.WindSpeed) * Inspeed8PulseAnemometer.MS_PER_HZ)); } lastWindSpeedSampleTime = time; } if (sample.WindDirection != null) { sampleBuffer.WindDirection.Add(new KeyValuePair <DateTime, double>( time, (double)sample.WindDirection)); } if (sample.SunshineDuration != null) { sampleBuffer.SunshineDuration.Add((bool)sample.SunshineDuration); } } catch { gpio.Write(config.errorLedPin, PinValue.High); } } })); threads.Add(new Thread(() => { if (config.IsSensorEnabled(AwsSensor.Rainfall)) { try { double rainfall = rainfallSensor.Sample(); if (lastRainfallSampleTime != null && lastRainfallSampleTime == time - TimeSpan.FromSeconds(1)) { sampleBuffer.Rainfall.Add(rainfall); } lastRainfallSampleTime = time; } catch { gpio.Write(config.errorLedPin, PinValue.High); } } })); foreach (Thread thread in threads) { thread.Start(); } foreach (Thread thread in threads) { thread.Join(); } }