diff --git a/cmd/fermentord/main.go b/cmd/fermentord/main.go index 0575add..431ef8b 100644 --- a/cmd/fermentord/main.go +++ b/cmd/fermentord/main.go @@ -80,20 +80,25 @@ func mainLoop(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream, config display.SetTemperature(reading) case ev := <-gpio.C: + var evs string + switch ev { case hw.DoorClosed: gpio.LightsOff() gpio.StartFan() ctrl.Resume() + evs = "DOOR_CLOSED" case hw.DoorOpened: ctrl.Pause() gpio.LightsOn() gpio.StopFan() + evs = "DOOR_OPENED" } b, err := json.Marshal(map[string]interface{}{ - "event": ev, + "time": time.Now().UTC(), + "event": evs, }) if err != nil { hub.CaptureException(err) diff --git a/internal/configuration/config.go b/internal/configuration/config.go index 07ec1f4..77a1a8d 100644 --- a/internal/configuration/config.go +++ b/internal/configuration/config.go @@ -56,11 +56,11 @@ func LoadConfiguration() *Configuration { defer hub.Flush(10 * time.Second) viper.SetDefault("http.port", 8000) - viper.SetDefault("nats.stream", "FERMENTOR") - viper.SetDefault("nats.subject.event", "FERMENTOR.event") - viper.SetDefault("nats.subject.state", "FERMENTOR.state") - viper.SetDefault("nats.subject.temp", "FERMENTOR.temp") - viper.SetDefault("nats.subject.tilt", "FERMENTOR.tilt") + viper.SetDefault("nats.stream", "DWJONDAHL") + viper.SetDefault("nats.subject.event", "DWJONDAHL.ingest.fermentor.event") + viper.SetDefault("nats.subject.state", "DWJONDAHL.ingest.fermentor.ingest_state") + viper.SetDefault("nats.subject.temp", "DWJONDAHL.ingest.fermentor.ingest_temperature_reading") + viper.SetDefault("nats.subject.tilt", "DWJONDAHL.ingest.fermentor.ingest_tilt_reading") viper.SetDefault("nats.url", "nats.service.consul") viper.SetDefault("pid.kd", 2.0) viper.SetDefault("pid.ki", 0.0001) diff --git a/internal/dwingest/nats.go b/internal/dwingest/nats.go index b4af7cc..e219cb5 100644 --- a/internal/dwingest/nats.go +++ b/internal/dwingest/nats.go @@ -47,12 +47,14 @@ func (p *DWIngest) Run(ctx context.Context, wg *sync.WaitGroup, js nats.JetStrea case state := <-p.chState: reading := State{ + Time: time.Now().UTC(), State: controllers.ChamberStateMap[state], } publish(config.NATS.Subject.State, js, hub, reading) case t := <-tilt.C: reading := Tilt{ + Time: time.Now().UTC(), Color: string(t.Color()), Gravity: t.Gravity(), Temperature: t.Celsius(), diff --git a/internal/dwingest/types.go b/internal/dwingest/types.go index 55bfe9b..04e3f7a 100644 --- a/internal/dwingest/types.go +++ b/internal/dwingest/types.go @@ -1,11 +1,15 @@ package dwingest +import "time" + type State struct { - State string `json:"state"` + Time time.Time `json:"time"` + State string `json:"state"` } type Tilt struct { - Color string `json:"color"` - Gravity float64 `json:"gravity"` - Temperature float64 `json:"temperature"` + Time time.Time `json:"time"` + Color string `json:"color"` + Gravity float64 `json:"gravity"` + Temperature float64 `json:"temperature"` }