diff --git a/cmd/fermentord/main.go b/cmd/fermentord/main.go index 1996348..b9af318 100644 --- a/cmd/fermentord/main.go +++ b/cmd/fermentord/main.go @@ -32,6 +32,10 @@ func main() { configuration.Initialize() config := configuration.LoadConfiguration() + if config.Brew.UUID.IsNil() { + log.Fatal("Brew ID is not configured -- terminating") + } + // NATS servers := strings.Join(config.NATS.Servers, ",") userInfo := nats.UserInfo(config.NATS.Username, config.NATS.Password) diff --git a/internal/configuration/global.go b/internal/configuration/global.go index 9229dba..f9f7d07 100644 --- a/internal/configuration/global.go +++ b/internal/configuration/global.go @@ -1,8 +1,15 @@ package configuration -import "github.com/spf13/viper" +import ( + "github.com/gofrs/uuid" + "github.com/spf13/viper" +) type Configuration struct { + Brew struct { + UUID uuid.UUID `mapstructure:"uuid"` + } `mapstructure:"brew"` + NATS struct { Servers []string `mapstructure:"servers"` Username string `mapstructure:"username"` diff --git a/internal/dwingest/nats.go b/internal/dwingest/nats.go index 3baeb97..342e829 100644 --- a/internal/dwingest/nats.go +++ b/internal/dwingest/nats.go @@ -135,6 +135,7 @@ func (p *DWIngest) publish(subject string, reading any) error { func (p *DWIngest) publishTilt(t tilt.Tilt) error { ev := Tilt{ Time: time.Now().UTC(), + BrewUUID: p.config.Brew.UUID, Color: string(t.Color()), Gravity: t.Gravity(), Temperature: t.Celsius(), @@ -144,13 +145,16 @@ func (p *DWIngest) publishTilt(t tilt.Tilt) error { } func (p *DWIngest) publishTemperatureReading(reading temperature.TemperatureReading) error { + reading.BrewUUID = p.config.Brew.UUID + return p.publish(p.config.NATS.Subject.Temp, reading) } func (p *DWIngest) publishState(state controllers.ChamberState) error { st := State{ - Time: time.Now().UTC(), - State: controllers.ChamberStateMap[state], + Time: time.Now().UTC(), + BrewUUID: p.config.Brew.UUID, + State: controllers.ChamberStateMap[state], } return p.publish(p.config.NATS.Subject.State, st) @@ -158,8 +162,9 @@ func (p *DWIngest) publishState(state controllers.ChamberState) error { func (p *DWIngest) publishEvent(event string) error { ev := Event{ - Time: time.Now().UTC(), - Event: event, + Time: time.Now().UTC(), + BrewUUID: p.config.Brew.UUID, + Event: event, } return p.publish(p.config.NATS.Subject.Event, ev) diff --git a/internal/dwingest/types.go b/internal/dwingest/types.go index 65fdd77..90b2288 100644 --- a/internal/dwingest/types.go +++ b/internal/dwingest/types.go @@ -1,20 +1,27 @@ package dwingest -import "time" +import ( + "time" + + "github.com/gofrs/uuid" +) type State struct { - Time time.Time `json:"time"` - State string `json:"state"` + Time time.Time `json:"time"` + BrewUUID uuid.UUID `json:"brew_uuid"` + State string `json:"state"` } type Tilt struct { Time time.Time `json:"time"` + BrewUUID uuid.UUID `json:"brew_uuid"` Color string `json:"color"` Gravity float64 `json:"gravity"` Temperature float64 `json:"temperature"` } type Event struct { - Time time.Time `json:"time"` - Event string `json:"event"` + Time time.Time `json:"time"` + BrewUUID uuid.UUID `json:"brew_uuid"` + Event string `json:"event"` } diff --git a/pkg/temperature/temperature.go b/pkg/temperature/temperature.go index 5abe698..f99d330 100644 --- a/pkg/temperature/temperature.go +++ b/pkg/temperature/temperature.go @@ -1,10 +1,15 @@ package temperature -import "time" +import ( + "time" + + "github.com/gofrs/uuid" +) type TemperatureReading struct { - Time time.Time `json:"time"` - Ambient float64 `json:"ambient"` - Chamber float64 `json:"chamber"` - Wort float64 `json:"wort"` + Time time.Time `json:"time"` + BrewUUID uuid.UUID `json:"brew_uuid"` + Ambient float64 `json:"ambient"` + Chamber float64 `json:"chamber"` + Wort float64 `json:"wort"` }