Skip to content

Commit

Permalink
* finally found the problem with EOF from the mqtt broker. It was, as I
Browse files Browse the repository at this point in the history
  should have realised much sooner, a case of duplicate mqtt client-id.
  • Loading branch information
johanix committed Sep 23, 2024
1 parent 29b945c commit 2498700
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
6 changes: 6 additions & 0 deletions configupdater.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import (

func (td *TemData) ConfigUpdater(conf *Config, stopch chan struct{}) {

active := viper.GetBool("tapir.config.active")
if !active {
td.Logger.Printf("*** ConfigUpdater: not active, skipping")
return
}

// Create a new mqtt engine just for the statusupdater.
me := td.MqttEngine
if me == nil {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ replace github.com/dnstapir/tapir => ../tapir
require (
github.com/dnstapir/tapir v0.0.0-00010101000000-000000000000
github.com/go-playground/validator/v10 v10.22.1
github.com/google/uuid v1.4.0
github.com/gorilla/mux v1.8.1
github.com/mattn/go-sqlite3 v1.14.23
github.com/miekg/dns v1.1.62
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0=
github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w=
github.com/gookit/goutil v0.6.16 h1:9fRMCF4X9abdRD5+2HhBS/GwafjBlTUBjRtA5dgkvuw=
Expand Down
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"syscall"
"time"

"github.com/google/uuid"
_ "github.com/mattn/go-sqlite3"
flag "github.com/spf13/pflag"
"github.com/spf13/viper"
Expand Down Expand Up @@ -121,12 +122,15 @@ func mainloop(conf *Config, configfile *string, td *TemData) {
}

var Gconfig Config
var mqttclientid string

func main() {
// var conf Config

mqttclientid = "tapir-pop-" + uuid.New().String()
flag.BoolVarP(&tapir.GlobalCF.Debug, "debug", "d", false, "Debug mode")
flag.BoolVarP(&tapir.GlobalCF.Verbose, "verbose", "v", false, "Verbose mode")
flag.StringVarP(&mqttclientid, "client-id", "", mqttclientid, "MQTT client id, default is a random string")

flag.Parse()

var cfgFileUsed string
Expand Down Expand Up @@ -195,7 +199,7 @@ func main() {

if td.MqttEngine == nil {
td.mu.Lock()
err := td.CreateMqttEngine(viper.GetString("tapir.mqtt.clientid"), statusch, td.MqttLogger)
err := td.CreateMqttEngine(mqttclientid, statusch, td.MqttLogger)
if err != nil {
TEMExiter("Error creating MQTT Engine: %v", err)
}
Expand Down
8 changes: 8 additions & 0 deletions statusupdater.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ import (

func (td *TemData) StatusUpdater(conf *Config, stopch chan struct{}) {

active := viper.GetBool("tapir.status.active")
if !active {
td.Logger.Printf("*** StatusUpdater: not active, will just read status updates from channel and not publish anything")
for csu := range td.ComponentStatusCh {
log.Printf("StatusUpdater: got status update message: %+v", csu)
}
}

var s = tapir.TapirFunctionStatus{
Function: "tapir-pop",
FunctionID: "random-popper",
Expand Down

0 comments on commit 2498700

Please sign in to comment.