Retain availability

This commit is contained in:
Łukasz Moskała 2024-12-22 20:35:07 +01:00
parent 0b1065e993
commit 74d2e3cb7c

View file

@ -33,7 +33,7 @@ func main() {
opts.OnConnect = connectHandler
opts.SetKeepAlive(20 * time.Second)
opts.SetAutoReconnect(true)
opts.SetWill("mqtt2exec/"+os.Args[2]+"/state", "offline", 1, false)
opts.SetWill("mqtt2exec/"+os.Args[2]+"/state", "offline", 1, true)
client := mqtt.NewClient(opts)
sleep := 1 * time.Second
for {
@ -72,5 +72,5 @@ func connectHandler(c mqtt.Client) {
if token.Error() != nil {
log.Printf("mqtt2exec: Error subscribing to topic: %s", token.Error())
}
c.Publish("mqtt2exec/"+os.Args[2]+"/state", 1, false, "online")
c.Publish("mqtt2exec/"+os.Args[2]+"/state", 1, true, "online")
}