Publish events to dwingest
This commit is contained in:
parent
fe94a51acd
commit
dd8a48905a
4 changed files with 21 additions and 10 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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"`
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue