Skip to content

Commit

Permalink
mqtt: (re-)subscribe to discover topic in onConnect() to ensure subsc…
Browse files Browse the repository at this point in the history
…ription on reconnect or if Discover() is called before first connection

config: use filepath instead of path when generating clientIdb
  • Loading branch information
bonan committed May 17, 2020
1 parent f1d7603 commit 49a591a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions transport/mqtt/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/google/uuid"
"net"
"os"
"path"
"path/filepath"
"strings"
"time"
)
Expand Down Expand Up @@ -49,7 +49,7 @@ func (c *Config) check() error {
var id string
if len(os.Args) > 0 && len(os.Args[0]) > 0 {
// Use executable name as first part of id
id = path.Base(os.Args[0])
id = filepath.Base(os.Args[0])
} else {
id = "htlib"
}
Expand Down
6 changes: 6 additions & 0 deletions transport/mqtt/mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ func (m *mqtt) onConnect(server string, _code byte, err error) {
}
}

if len(m.discoverSub) > 0 {
m.client.Subscribe(
&libmqtt.Topic{Name: m.discoverTopic},
)
}

if m.deviceState != nil {
m.sendDiscover()
}
Expand Down

0 comments on commit 49a591a

Please sign in to comment.