/// <summary> /// Opens the data logger. /// </summary> /// <returns> /// <see langword="false"/> if any of the sensors failed to open, otherwise <see langword="true"/>. /// </returns> /// <exception cref="InvalidOperationException"> /// Thrown if the data logger is already open. /// </exception> public bool Open() { if (IsOpen) { throw new InvalidOperationException("The data logger is already open"); } IsOpen = true; bool success = true; if (config.IsSensorEnabled(AwsSensor.AirTemperature)) { try { airTempSensor = new Mcp9808(); airTempSensor.Open(); } catch { gpio.Write(config.errorLedPin, PinValue.High); LogMessage("Failed to open airTemp sensor"); success = false; } } if (config.IsSensorEnabled(AwsSensor.RelativeHumidity)) { try { relHumSensor = new Htu21d(); relHumSensor.Open(); } catch { gpio.Write(config.errorLedPin, PinValue.High); LogMessage("Failed to open relHum sensor"); success = false; } } if (config.IsSensorEnabled(AwsSensor.Satellite)) { SatelliteConfiguration satConfig = new SatelliteConfiguration(); if (config.IsSensorEnabled(AwsSensor.WindSpeed)) { satConfig.WindSpeedEnabled = true; satConfig.WindSpeedPin = (int)config.sensors.satellite.windSpeed.pin; } if (config.IsSensorEnabled(AwsSensor.WindDirection)) { satConfig.WindDirectionEnabled = true; satConfig.WindDirectionPin = (int)config.sensors.satellite.windDir.pin; } if (config.IsSensorEnabled(AwsSensor.SunshineDuration)) { satConfig.SunshineDurationEnabled = true; satConfig.SunshineDurationPin = (int)config.sensors.satellite.sunDur.pin; } try { satellite = new Satellite((int)config.sensors.satellite.port, satConfig); satellite.Open(); } catch { gpio.Write(config.errorLedPin, PinValue.High); LogMessage("Failed to open satellite sensor"); success = false; } } if (config.IsSensorEnabled(AwsSensor.Rainfall)) { try { rainfallSensor = new RainwiseRainew111( (int)config.sensors.rainfall.pin, gpio); rainfallSensor.Open(); } catch { gpio.Write(config.errorLedPin, PinValue.High); LogMessage("Failed to open rainfall sensor"); success = false; } } if (config.IsSensorEnabled(AwsSensor.StationPressure)) { try { staPresSensor = new Bmp280(); staPresSensor.Open(); } catch { gpio.Write(config.errorLedPin, PinValue.High); LogMessage("Failed to open BMP280 sensor"); success = false; } } return(success); }