Clean up config

This commit is contained in:
Søren Rasmussen 2022-03-11 20:43:59 +01:00
parent f8369b4bd0
commit e5d5b6ca2f

View file

@ -14,28 +14,28 @@ func loadConfiguration() *controllers.ControllerConfig {
hub := sentry.CurrentHub().Clone() hub := sentry.CurrentHub().Clone()
defer hub.Flush(10 * time.Second) defer hub.Flush(10 * time.Second)
viper.SetDefault("http.port", 8000)
viper.SetDefault("main.data_path", "./data.txt") viper.SetDefault("main.data_path", "./data.txt")
viper.SetDefault("nats.url", "nats.service.consul")
viper.SetDefault("nats.stream", "FERMENTOR") viper.SetDefault("nats.stream", "FERMENTOR")
viper.SetDefault("nats.subject.state", "FERMENTOR.state") viper.SetDefault("nats.subject.state", "FERMENTOR.state")
viper.SetDefault("nats.subject.temp", "FERMENTOR.temp") viper.SetDefault("nats.subject.temp", "FERMENTOR.temp")
viper.SetDefault("http.port", 8000) viper.SetDefault("nats.url", "nats.service.consul")
viper.SetDefault("pid.kp", 2.0)
viper.SetDefault("pid.ki", 0.0001)
viper.SetDefault("pid.kd", 2.0) viper.SetDefault("pid.kd", 2.0)
viper.SetDefault("limits.min_chamber_temp", 5) viper.SetDefault("pid.ki", 0.0001)
viper.SetDefault("pid.kp", 2.0)
viper.SetDefault("limits.heater_grace_time_secs", 1800)
viper.SetDefault("limits.max_chamber_temp", 40) viper.SetDefault("limits.max_chamber_temp", 40)
viper.SetDefault("limits.min_cooler_runtime_secs", 300)
viper.SetDefault("limits.max_cooler_runtime_secs", 86400) viper.SetDefault("limits.max_cooler_runtime_secs", 86400)
viper.SetDefault("limits.min_chamber_temp", 5)
viper.SetDefault("limits.min_cooler_cooldown_secs", 300) viper.SetDefault("limits.min_cooler_cooldown_secs", 300)
viper.SetDefault("liimts.heater_grace_time_secs", 1800) viper.SetDefault("limits.min_cooler_runtime_secs", 300)
viper.SetDefault("sensors.weight", 0.8)
viper.AddConfigPath("/etc") viper.AddConfigPath("/etc")
viper.AddConfigPath("/usr/local/etc") viper.AddConfigPath("/usr/local/etc")
viper.AddConfigPath(".") viper.AddConfigPath(".")
viper.SetConfigName("fermentord") viper.SetConfigName("fermentord")
viper.SetConfigType("toml") viper.SetConfigType("toml")
//viper.AutomaticEnv()
if err := viper.ReadInConfig(); err != nil { if err := viper.ReadInConfig(); err != nil {
log.Printf("Error loading configuration: %v", err) log.Printf("Error loading configuration: %v", err)
@ -47,25 +47,16 @@ func loadConfiguration() *controllers.ControllerConfig {
log.Fatal(err) log.Fatal(err)
} }
log.Printf("Min chamber temp : %v", config.Limits.MinChamberTemperature)
log.Printf("Max chamber temp : %v", config.Limits.MaxChamberTemperature)
log.Printf("Fermentation temp: %v", config.FermentationTemperature)
log.Printf("Delta temp cool : %v", config.DeltaTemperatureCool)
log.Printf("Delta temp heat : %v", config.DeltaTemperatureHeat)
return config return config
} }
func reloadConfiguration(config *controllers.ControllerConfig, ctrl *controllers.ChamberController) { func reloadConfiguration(config *controllers.ControllerConfig, ctrl *controllers.ChamberController) {
log.Printf("Reloading configuration") log.Printf("Reloading configuration")
log.Printf("Ambient sensor: %v", config.Sensor.Ambient)
log.Printf("Chamber sensor: %v", config.Sensor.Chamber)
log.Printf("Wort sensor : %v", config.Sensor.Wort)
temperature.ConfigUpdates <- []string{ temperature.ConfigUpdates <- []string{
config.Sensor.Ambient, config.Sensors.Ambient,
config.Sensor.Chamber, config.Sensors.Chamber,
config.Sensor.Wort, config.Sensors.Wort,
} }
ctrl.ConfigUpdates <- *config ctrl.ConfigUpdates <- *config