diff --git a/backend/services/mochi/cmd/main.go b/backend/services/mochi/cmd/main.go index 37412ec..f938cf0 100644 --- a/backend/services/mochi/cmd/main.go +++ b/backend/services/mochi/cmd/main.go @@ -225,6 +225,7 @@ func (h *MyHook) Provides(b byte) bool { return bytes.Contains([]byte{ mqtt.OnSubscribed, mqtt.OnDisconnect, + mqtt.OnClientExpired, }, []byte{b}) } @@ -233,6 +234,10 @@ func (h *MyHook) Init(config any) error { return nil } +func (h *MyHook) OnClientExpired(cl *mqtt.Client) { + log.Printf("Client id %s expired", cl.ID) +} + func (h *MyHook) OnDisconnect(cl *mqtt.Client, err error, expire bool) { var clUser string if len(cl.Properties.Props.User) > 0 { @@ -257,6 +262,10 @@ func (h *MyHook) OnSubscribed(cl *mqtt.Client, pk packets.Packet, reasonCodes [] } if clUser != "" { + cl.Properties.Will = mqtt.Will{ + Qos: 1, + Payload: []byte(clUser), + } log.Println("new device:", clUser) err := server.Publish("oktopus/devices", []byte(clUser), false, 1) if err != nil {