Add brew UUID to DWIngest
This commit is contained in:
parent
c38b8e1ae6
commit
1366730593
5 changed files with 43 additions and 15 deletions
|
@ -32,6 +32,10 @@ func main() {
|
||||||
configuration.Initialize()
|
configuration.Initialize()
|
||||||
config := configuration.LoadConfiguration()
|
config := configuration.LoadConfiguration()
|
||||||
|
|
||||||
|
if config.Brew.UUID.IsNil() {
|
||||||
|
log.Fatal("Brew ID is not configured -- terminating")
|
||||||
|
}
|
||||||
|
|
||||||
// NATS
|
// NATS
|
||||||
servers := strings.Join(config.NATS.Servers, ",")
|
servers := strings.Join(config.NATS.Servers, ",")
|
||||||
userInfo := nats.UserInfo(config.NATS.Username, config.NATS.Password)
|
userInfo := nats.UserInfo(config.NATS.Username, config.NATS.Password)
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
package configuration
|
package configuration
|
||||||
|
|
||||||
import "github.com/spf13/viper"
|
import (
|
||||||
|
"github.com/gofrs/uuid"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
type Configuration struct {
|
type Configuration struct {
|
||||||
|
Brew struct {
|
||||||
|
UUID uuid.UUID `mapstructure:"uuid"`
|
||||||
|
} `mapstructure:"brew"`
|
||||||
|
|
||||||
NATS struct {
|
NATS struct {
|
||||||
Servers []string `mapstructure:"servers"`
|
Servers []string `mapstructure:"servers"`
|
||||||
Username string `mapstructure:"username"`
|
Username string `mapstructure:"username"`
|
||||||
|
|
|
@ -135,6 +135,7 @@ func (p *DWIngest) publish(subject string, reading any) error {
|
||||||
func (p *DWIngest) publishTilt(t tilt.Tilt) error {
|
func (p *DWIngest) publishTilt(t tilt.Tilt) error {
|
||||||
ev := Tilt{
|
ev := Tilt{
|
||||||
Time: time.Now().UTC(),
|
Time: time.Now().UTC(),
|
||||||
|
BrewUUID: p.config.Brew.UUID,
|
||||||
Color: string(t.Color()),
|
Color: string(t.Color()),
|
||||||
Gravity: t.Gravity(),
|
Gravity: t.Gravity(),
|
||||||
Temperature: t.Celsius(),
|
Temperature: t.Celsius(),
|
||||||
|
@ -144,13 +145,16 @@ func (p *DWIngest) publishTilt(t tilt.Tilt) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *DWIngest) publishTemperatureReading(reading temperature.TemperatureReading) error {
|
func (p *DWIngest) publishTemperatureReading(reading temperature.TemperatureReading) error {
|
||||||
|
reading.BrewUUID = p.config.Brew.UUID
|
||||||
|
|
||||||
return p.publish(p.config.NATS.Subject.Temp, reading)
|
return p.publish(p.config.NATS.Subject.Temp, reading)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *DWIngest) publishState(state controllers.ChamberState) error {
|
func (p *DWIngest) publishState(state controllers.ChamberState) error {
|
||||||
st := State{
|
st := State{
|
||||||
Time: time.Now().UTC(),
|
Time: time.Now().UTC(),
|
||||||
State: controllers.ChamberStateMap[state],
|
BrewUUID: p.config.Brew.UUID,
|
||||||
|
State: controllers.ChamberStateMap[state],
|
||||||
}
|
}
|
||||||
|
|
||||||
return p.publish(p.config.NATS.Subject.State, st)
|
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 {
|
func (p *DWIngest) publishEvent(event string) error {
|
||||||
ev := Event{
|
ev := Event{
|
||||||
Time: time.Now().UTC(),
|
Time: time.Now().UTC(),
|
||||||
Event: event,
|
BrewUUID: p.config.Brew.UUID,
|
||||||
|
Event: event,
|
||||||
}
|
}
|
||||||
|
|
||||||
return p.publish(p.config.NATS.Subject.Event, ev)
|
return p.publish(p.config.NATS.Subject.Event, ev)
|
||||||
|
|
|
@ -1,20 +1,27 @@
|
||||||
package dwingest
|
package dwingest
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gofrs/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
type State struct {
|
type State struct {
|
||||||
Time time.Time `json:"time"`
|
Time time.Time `json:"time"`
|
||||||
State string `json:"state"`
|
BrewUUID uuid.UUID `json:"brew_uuid"`
|
||||||
|
State string `json:"state"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Tilt struct {
|
type Tilt struct {
|
||||||
Time time.Time `json:"time"`
|
Time time.Time `json:"time"`
|
||||||
|
BrewUUID uuid.UUID `json:"brew_uuid"`
|
||||||
Color string `json:"color"`
|
Color string `json:"color"`
|
||||||
Gravity float64 `json:"gravity"`
|
Gravity float64 `json:"gravity"`
|
||||||
Temperature float64 `json:"temperature"`
|
Temperature float64 `json:"temperature"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Event struct {
|
type Event struct {
|
||||||
Time time.Time `json:"time"`
|
Time time.Time `json:"time"`
|
||||||
Event string `json:"event"`
|
BrewUUID uuid.UUID `json:"brew_uuid"`
|
||||||
|
Event string `json:"event"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
package temperature
|
package temperature
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gofrs/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
type TemperatureReading struct {
|
type TemperatureReading struct {
|
||||||
Time time.Time `json:"time"`
|
Time time.Time `json:"time"`
|
||||||
Ambient float64 `json:"ambient"`
|
BrewUUID uuid.UUID `json:"brew_uuid"`
|
||||||
Chamber float64 `json:"chamber"`
|
Ambient float64 `json:"ambient"`
|
||||||
Wort float64 `json:"wort"`
|
Chamber float64 `json:"chamber"`
|
||||||
|
Wort float64 `json:"wort"`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue