Ejemplo n.º 1
0
        public async Task StartAsync(CancellationToken token)
        {
            while (!token.IsCancellationRequested)
            {
                // wait for some reading before publish
                await Task.Delay(TimeSpan.FromMinutes(_settingsMgmt.GetSettings().PublishInterval), token);

                try
                {
                    await PublishValues(token);
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "Exception checking temperature.");
                }
            }
        }
Ejemplo n.º 2
0
        private void StoreTemperature()
        {
            _settings = _settingsMgmt.GetSettings();
            var tempIn  = GetTemperatureFromFile(Path.Combine(_settings.PollingSensorsPath, _settings.SensorInsideId, _settings.PollingTemperatureFile));
            var tempOut = GetTemperatureFromFile(Path.Combine(_settings.PollingSensorsPath, _settings.SensorOutsideId, _settings.PollingTemperatureFile));

            DataAccess.Insert(new Temperature
            {
                Inside    = tempIn,
                Outside   = tempOut,
                Timestamp = DateTime.Now
            });
            _logger.LogInformation($"Temp IN : {tempIn} , Temp OUT {tempOut}");
        }
Ejemplo n.º 3
0
        public SettingsModule(SettingsManagement settingsMgmt) : base("/api/_settings")
        {
            _settingsMgmt = settingsMgmt;
            Get("/", (p) =>
            {
                var settings = _settingsMgmt.GetSettings();
                return(Negotiate.WithModel(new SettingsRequest
                {
                    PollingInterval = settings.PollingInterval,
                    PollingSensorsPath = settings.PollingSensorsPath,
                    PollingTemperatureFile = settings.PollingTemperatureFile,
                    SensorInsideId = settings.SensorInsideId,
                    SensorOutsideId = settings.SensorOutsideId,
                    TargetTemperature = settings.TargetTemperature,
                    PinCool = settings.PinCool,
                    PinHeat = settings.PinHeat,
                    Diff = settings.Diff
                }));
            });

            Put("/", (p) =>
            {
                var req                         = this.Bind <SettingsRequest>();
                var settings                    = _settingsMgmt.GetSettings();
                settings.PollingInterval        = req.PollingInterval == default(int) ? settings.PollingInterval : req.PollingInterval;
                settings.PollingSensorsPath     = req.PollingSensorsPath ?? settings.PollingSensorsPath;
                settings.PollingTemperatureFile = req.PollingTemperatureFile ?? settings.PollingTemperatureFile;
                settings.SensorInsideId         = req.SensorInsideId ?? settings.SensorInsideId;
                settings.SensorOutsideId        = req.SensorOutsideId ?? settings.SensorOutsideId;
                settings.TargetTemperature      = req.TargetTemperature == default(float) ? settings.TargetTemperature : req.TargetTemperature;
                settings.PinCool                = req.PinCool == default(int) ? settings.PinCool : req.PinCool;
                settings.PinHeat                = req.PinHeat == default(int) ? settings.PinHeat : req.PinHeat;
                settings.Diff                   = req.Diff == default(float) ? settings.Diff : req.Diff;
                settingsMgmt.UpdateSettings(settings);
                return(Negotiate.WithStatusCode(HttpStatusCode.OK));
            });
        }
Ejemplo n.º 4
0
        public async Task StartAsync(CancellationToken token)
        {
            while (!token.IsCancellationRequested)
            {
                // Wait for some reading before check
                await Task.Delay(TimeSpan.FromMinutes(_settingsMgmt.GetSettings().PublishInterval), token);

                try
                {
                    await Check();
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "Exception checking temperature.");
                }
            }
            // gracefully shutdown
            await CoolOff();
            await HeatOff();
        }