protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            // This will cause the loop to stop if the service is stopped
            while (!stoppingToken.IsCancellationRequested)
            {
                try
                {
                    //var humidityReading = (HumidityTemperatureReading)_sensorClient
                    //    .GetSensorReading(new SensorReadingByGpioOptions() {GpioPin = _options.HumiditySensorGpio });

                    var relayRequest = new ToggleRelayStateRequest
                    {
                        GpioPin = _options.RelayGpio,
                        State   = RelayState.On
                    };

                    if (_relayClient.GetRelayState(_options.RelayGpio) == RelayState.On)
                    {
                        relayRequest.State = RelayState.Off;
                    }

                    _relayClient.ToggleRelayState(relayRequest);
                }
                catch (Exception ex)
                {
                    //need a logger eventually...
                }
                finally
                {
                    await Task.Delay(TimeSpan.FromMinutes(_options.CheckInterval), stoppingToken);
                }
            }
        }
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                _options = (HumidifierPressureAltitudeTemperatureJobOptions)
                           JobStateHelper.JobStateHelper
                           .GetJobByName("HumidifierPressureAltitudeTemperatureJob").JobOptions;

                try
                {
                    var humidityReading = (HumidityTemperatureAltitudePressureReading)_sensorClient
                                          .GetSensorReading(new SensorReadingByGpioI2COptions()
                    {
                        GpioPin = _options.HumiditySensorGpio
                    });

                    var relayRequest = new ToggleRelayStateRequest
                    {
                        GpioPin = _options.RelayGpio,
                        State   = RelayState.Off
                    };

                    if (humidityReading.Humidity < _options.TargetHumidity)
                    {
                        relayRequest.State = RelayState.On;
                    }

                    _relayClient.ToggleRelayState(relayRequest);
                }
                catch (Exception ex)
                {
                    // need a logger eventually...
                }
                finally
                {
                    var lastRun = DateTime.UtcNow;
                    JobStateHelper.JobStateHelper.AddOrUpdateJobState(new JobState
                    {
                        LastRunTime = lastRun,
                        NextRunTime = lastRun.AddMinutes(_options.CheckInterval),
                        JobOptions  = _options
                    }, nameof(HumidifierPressureAltitudeTemperatureJob));

                    await Task.Delay(TimeSpan.FromMinutes(_options.CheckInterval), stoppingToken);
                }
            }
        }
示例#3
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                _options = (FanJobOptions)JobStateHelper.JobStateHelper.GetJobByName("FanJob").JobOptions;

                try
                {
                    var relayRequest = new ToggleRelayStateRequest
                    {
                        GpioPin = _options.RelayGpioPin,
                        State   = RelayState.On
                    };

                    _relayClient.ToggleRelayState(relayRequest);

                    await Task.Delay(TimeSpan.FromMinutes(_options.RunDuration), stoppingToken);

                    relayRequest.State = RelayState.Off;

                    _relayClient.ToggleRelayState(relayRequest);
                }
                catch (Exception ex)
                {
                    // need a logger eventually...
                }
                finally
                {
                    var lastRun = DateTime.UtcNow;
                    JobStateHelper.JobStateHelper.AddOrUpdateJobState(new JobState
                    {
                        LastRunTime = lastRun,
                        NextRunTime = lastRun.AddMinutes(_options.RunInterval),
                        JobOptions  = _options
                    }, nameof(FanJob));

                    await Task.Delay(TimeSpan.FromMinutes(_options.RunInterval), stoppingToken);
                }
            }
        }