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,12 +145,15 @@ 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(),
|
||||||
|
BrewUUID: p.config.Brew.UUID,
|
||||||
State: controllers.ChamberStateMap[state],
|
State: controllers.ChamberStateMap[state],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,6 +163,7 @@ 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(),
|
||||||
|
BrewUUID: p.config.Brew.UUID,
|
||||||
Event: event,
|
Event: event,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,20 @@
|
||||||
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"`
|
||||||
|
BrewUUID uuid.UUID `json:"brew_uuid"`
|
||||||
State string `json:"state"`
|
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"`
|
||||||
|
@ -16,5 +22,6 @@ type Tilt struct {
|
||||||
|
|
||||||
type Event struct {
|
type Event struct {
|
||||||
Time time.Time `json:"time"`
|
Time time.Time `json:"time"`
|
||||||
|
BrewUUID uuid.UUID `json:"brew_uuid"`
|
||||||
Event string `json:"event"`
|
Event string `json:"event"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
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"`
|
||||||
|
BrewUUID uuid.UUID `json:"brew_uuid"`
|
||||||
Ambient float64 `json:"ambient"`
|
Ambient float64 `json:"ambient"`
|
||||||
Chamber float64 `json:"chamber"`
|
Chamber float64 `json:"chamber"`
|
||||||
Wort float64 `json:"wort"`
|
Wort float64 `json:"wort"`
|
||||||
|
|
Loading…
Reference in a new issue