Support NATS cluster
This commit is contained in:
parent
d873538b70
commit
0b3d35721e
4 changed files with 11 additions and 9 deletions
|
@ -34,7 +34,7 @@ func mainLoop(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream, config
|
||||||
defer display.Close()
|
defer display.Close()
|
||||||
|
|
||||||
// Controller
|
// Controller
|
||||||
ctrl := controllers.NewChamberController("Chamber 1", *config)
|
ctrl := controllers.NewChamberController(*config)
|
||||||
|
|
||||||
// Configuration reload
|
// Configuration reload
|
||||||
loadConfiguration := func() {
|
loadConfiguration := func() {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -31,7 +32,9 @@ func main() {
|
||||||
config := configuration.LoadConfiguration()
|
config := configuration.LoadConfiguration()
|
||||||
|
|
||||||
// NATS
|
// NATS
|
||||||
nc, err := nats.Connect(config.NATS.URL)
|
servers := strings.Join(config.NATS.Servers, ",")
|
||||||
|
userInfo := nats.UserInfo(config.NATS.Username, config.NATS.Password)
|
||||||
|
nc, err := nats.Connect(servers, userInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,9 @@ import (
|
||||||
|
|
||||||
type Configuration struct {
|
type Configuration struct {
|
||||||
NATS struct {
|
NATS struct {
|
||||||
URL string `mapstructure:"url"`
|
Servers []string `mapstructure:"servers"`
|
||||||
|
Username string `mapstructure:"username"`
|
||||||
|
Password string `mapstructure:"password"`
|
||||||
Stream string `mapstructure:"stream"`
|
Stream string `mapstructure:"stream"`
|
||||||
Subject struct {
|
Subject struct {
|
||||||
Event string `mapstructure:"event"`
|
Event string `mapstructure:"event"`
|
||||||
|
|
|
@ -36,8 +36,6 @@ type ChamberController struct {
|
||||||
C chan ChamberState
|
C chan ChamberState
|
||||||
isPaused bool
|
isPaused bool
|
||||||
|
|
||||||
name string
|
|
||||||
|
|
||||||
// Current temperature readings.
|
// Current temperature readings.
|
||||||
ambientTemperature float64
|
ambientTemperature float64
|
||||||
chamberTemperature float64
|
chamberTemperature float64
|
||||||
|
@ -50,10 +48,9 @@ type ChamberController struct {
|
||||||
hub *sentry.Hub
|
hub *sentry.Hub
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewChamberController(name string, config configuration.Configuration) *ChamberController {
|
func NewChamberController(config configuration.Configuration) *ChamberController {
|
||||||
return &ChamberController{
|
return &ChamberController{
|
||||||
C: make(chan ChamberState),
|
C: make(chan ChamberState),
|
||||||
name: name,
|
|
||||||
config: config,
|
config: config,
|
||||||
pid: NewPIDController(config.PID.Kp, config.PID.Ki, config.PID.Kd),
|
pid: NewPIDController(config.PID.Kp, config.PID.Ki, config.PID.Kd),
|
||||||
chTemp: make(chan temperature.TemperatureReading),
|
chTemp: make(chan temperature.TemperatureReading),
|
||||||
|
|
Loading…
Reference in a new issue