diff --git a/pkg/daemon/daemon.go b/pkg/daemon/daemon.go index 14d7173..cdbf22c 100644 --- a/pkg/daemon/daemon.go +++ b/pkg/daemon/daemon.go @@ -16,19 +16,6 @@ import ( func Start(cnf *config.Config, flogger logger.Logger) error { - sensors := make([]sensor.Sensor, 0) - for _, cnfSensor := range cnf.Sensors { - if !cnfSensor.Enabled { - continue - } - - sensor, err := sensor.New(cnfSensor) - if err != nil { - return err - } - sensors = append(sensors, sensor) - } - measuredValueChannel := make(chan *types.MeasuredValue, 0) // load storage endpoint @@ -42,30 +29,29 @@ func Start(cnf *config.Config, flogger logger.Logger) error { return err } + repoSensors, err := repo.GetSensors() + if err != nil { + return err + } + + sensors := make([]sensor.Sensor, 0) + for _, repoSensor := range repoSensors { + if !repoSensor.Enabled { + continue + } + + sensor, err := sensor.New(repoSensor) + if err != nil { + return err + } + sensors = append(sensors, sensor) + } + interruptChannel := make(chan os.Signal, 1) signal.Notify(interruptChannel, os.Kill, syscall.SIGTERM) // Collection parentCtx := context.Background() - - // Insert device if not exist - device, _ := repo.GetDevice(cnf.Device.ID) - if device == nil { - if err := repo.AddDevices(cnf.Device); err != nil { - return err - } - } - - // Insert sensors if not exist - for _, cnfSensor := range cnf.Sensors { - sensor, _ := repo.GetSensor(cnfSensor.ID) - if sensor == nil { - if err := repo.AddSensors(cnfSensor); err != nil { - return err - } - } - } - ctx, cancel := context.WithCancel(parentCtx) for _, s := range sensors {