From a99590823b301d930533128ace8868e28e6062a9 Mon Sep 17 00:00:00 2001 From: seydx Date: Wed, 14 Jan 2026 19:11:53 +0100 Subject: [PATCH] allow to specify custom port --- pkg/wyze/client.go | 8 +++++++- pkg/wyze/tutk/conn.go | 8 ++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/wyze/client.go b/pkg/wyze/client.go index 4f81a395..fe150d2c 100644 --- a/pkg/wyze/client.go +++ b/pkg/wyze/client.go @@ -7,6 +7,7 @@ import ( "fmt" "net" "net/url" + "strconv" "strings" "sync" "time" @@ -278,11 +279,16 @@ func (c *Client) Close() error { func (c *Client) connect() error { host := c.host + port := 0 + if idx := strings.Index(host, ":"); idx > 0 { + if p, err := strconv.Atoi(host[idx+1:]); err == nil { + port = p + } host = host[:idx] } - conn, err := tutk.Dial(host, c.uid, c.authKey, c.enr, c.mac, c.verbose) + conn, err := tutk.Dial(host, port, c.uid, c.authKey, c.enr, c.mac, c.verbose) if err != nil { return fmt.Errorf("wyze: connect failed: %w", err) } diff --git a/pkg/wyze/tutk/conn.go b/pkg/wyze/tutk/conn.go index 539a5a66..6aaa0ad2 100644 --- a/pkg/wyze/tutk/conn.go +++ b/pkg/wyze/tutk/conn.go @@ -78,7 +78,7 @@ type Conn struct { cmdAck func() } -func Dial(host, uid, authKey, enr, mac string, verbose bool) (*Conn, error) { +func Dial(host string, port int, uid, authKey, enr, mac string, verbose bool) (*Conn, error) { udp, err := net.ListenUDP("udp", nil) if err != nil { return nil, err @@ -89,9 +89,13 @@ func Dial(host, uid, authKey, enr, mac string, verbose bool) (*Conn, error) { ctx, cancel := context.WithCancel(context.Background()) psk := derivePSK(enr) + if port == 0 { + port = DefaultPort + } + c := &Conn{ conn: udp, - addr: &net.UDPAddr{IP: net.ParseIP(host), Port: DefaultPort}, + addr: &net.UDPAddr{IP: net.ParseIP(host), Port: port}, rid: genRandomID(), uid: uid, authKey: authKey,