diff --git a/client/getDevice.go b/client/getDevice.go index 0573d068..3f79e5ab 100644 --- a/client/getDevice.go +++ b/client/getDevice.go @@ -21,6 +21,7 @@ import ( "crypto/x509" "errors" "fmt" + "strings" "github.com/plgd-dev/device/v2/client/core" "github.com/plgd-dev/device/v2/pkg/net/coap" @@ -92,7 +93,7 @@ type DeviceWithLinks struct { } func (c *Client) getDevicesByIP(ctx context.Context, ip string, expectedDeviceID string) ([]DeviceWithLinks, error) { - devs, err := c.getDeviceByIPWithUpdateCache(ctx, ip, expectedDeviceID) + devs, err := c.getDeviceByIPWithUpdateCache(ctx, strings.Trim(ip, "[]"), expectedDeviceID) if err != nil { return nil, err } diff --git a/client/observeDevices.go b/client/observeDevices.go index a272b7a1..6c846bc8 100644 --- a/client/observeDevices.go +++ b/client/observeDevices.go @@ -20,6 +20,7 @@ import ( "context" "errors" "fmt" + "strings" "sync" "github.com/google/uuid" @@ -220,7 +221,7 @@ func (o *devicesObserver) observe(ctx context.Context) (map[string]uint8, error) for deviceID, ip := range devicesByIP { go func(deviceID string, ip string) { defer wg.Done() - if _, e := o.c.getDeviceByIPWithUpdateCache(ctx, ip, deviceID); e == nil { + if _, e := o.c.getDeviceByIPWithUpdateCache(ctx, strings.Trim(ip, "[]"), deviceID); e == nil { newDevices.devices.LoadOrStore(deviceID, struct{}{}) } }(deviceID, ip)