New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MQTT: how do I resubscribe after reconnect? #570
Comments
// +build example
//
// Do not build by default.
package main
import (
"fmt"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/platforms/mqtt"
)
func main() {
mqttAdaptor := mqtt.NewAdaptor("tcp://localhost:1883", "pinger")
work := func() {
mqttAdaptor.On("hello", func(msg mqtt.Message) {
fmt.Println("hello")
})
mqttAdaptor.On("hola", func(msg mqtt.Message) {
fmt.Println("hola")
})
data := []byte("o")
gobot.Every(1*time.Second, func() {
mqttAdaptor.Publish("hello", data)
})
gobot.Every(5*time.Second, func() {
mqttAdaptor.Publish("hola", data)
})
}
robot := gobot.NewRobot("mqttBot",
[]gobot.Connection{mqttAdaptor},
work,
)
robot.Start()
} several seconds after stopping mqtt server, reconnect will happen. But Work no longer works |
@trevrosen this is one of the things we want to be able to solve with your latest work in progress. |
@deadprogram indeed! Speaking of which you want me to proceed to PR w/ the implementation basically as it stands? Should we talk through some implications for existing installs etc? |
Any update on this? |
I use two settings and it looks fine to my case. (gobot v1.12.0) mqttAdaptor.SetAutoReconnect(true)
mqttAdaptor.SetCleanSession(false) and workaround for resubscribe topic (the same client id) gobot.Every(30*time.Second, func() {
mqttAdaptor.On("hello", func(msg mqtt.Message) {
fmt.Println("hello")
})
}) |
@neewbee sorry for my silence on this -- it fell through the cracks. There's a new construct in the |
No description provided.
The text was updated successfully, but these errors were encountered: