diff --git a/pkg/gateway/lwm2m/client/lwm2m.go b/pkg/gateway/lwm2m/client/lwm2m.go index 2ae79db78..b0f8bbc16 100644 --- a/pkg/gateway/lwm2m/client/lwm2m.go +++ b/pkg/gateway/lwm2m/client/lwm2m.go @@ -150,7 +150,7 @@ func (c *Client) connect() error { udpClientOpts = append( udpClientOpts, - options.WithInactivityMonitor(time.Minute, func(cc *udpClient.Conn) { + options.WithInactivityMonitor(time.Second*time.Duration(c.Settings.UpdateIntervalSec), func(cc *udpClient.Conn) { logger.Warn("Connection inactive, triggering reconnect") select { case c.reconnectCh <- struct{}{}: @@ -240,11 +240,6 @@ func (c *Client) Register() error { c.locationPath = locationPath c.lastUpdatedTime = time.Now() - go func() { - if err := c.AutoUpdate(); err != nil { - logger.Errorf("failed to auto update registration: %v", err) - } - }() logger.Infof("register %v success", c.locationPath) return nil @@ -271,26 +266,6 @@ func (c *Client) Delete() error { return nil } -// AutoUpdate auto update registration -// Reference: https://www.openmobilealliance.org/release/LightweightM2M/V1_0-20170208-A/OMA-TS-LightweightM2M-V1_0-20170208-A.pdf#page=30 -func (c *Client) AutoUpdate() error { - ticker := time.NewTicker(time.Duration(c.Settings.UpdateIntervalSec) * time.Second) - for { - select { - case <-c.ctx.Done(): - return nil - case <-ticker.C: - if c.isActivity() { - if err := c.Update(); err != nil { - logger.Errorf("failed to update registration: %v", err) - continue - } - logger.Debug("update registration success") - } - } - } -} - // Update update registration // Reference: https://www.openmobilealliance.org/release/LightweightM2M/V1_0-20170208-A/OMA-TS-LightweightM2M-V1_0-20170208-A.pdf#page=30 // Reference: https://www.openmobilealliance.org/release/LightweightM2M/V1_0-20170208-A/OMA-TS-LightweightM2M-V1_0-20170208-A.pdf#page=76