From d82945098b4a8e272f99a5618580cdf5f08f7047 Mon Sep 17 00:00:00 2001 From: Thomas Klaehn Date: Sat, 11 Apr 2026 07:43:45 +0200 Subject: [PATCH] Fix IPv6 zone ID encoding in broker URL The zone identifier in fe80::%eth0 must be percent-encoded as %25 in a URL so Go's url.Parse accepts it. Without this, paho.mqtt.golang silently drops the broker and reports "no servers defined to connect to". Co-Authored-By: Claude Sonnet 4.6 --- main.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index d4bc422..05b11dc 100644 --- a/main.go +++ b/main.go @@ -368,7 +368,10 @@ func main() { h := newHandler(cfg) dialTarget := cfg.Broker if cfg.BrokerIP != "" { - dialTarget = "[" + cfg.BrokerIP + "]" + // URL-encode the zone ID separator so Go's url.Parse accepts it. + // net.Dial receives the unescaped form and handles the zone correctly. + encodedIP := strings.ReplaceAll(cfg.BrokerIP, "%", "%25") + dialTarget = "[" + encodedIP + "]" } brokerURL := fmt.Sprintf("ssl://%s:%d", dialTarget, cfg.Port) topic := cfg.TopicPrefix + "/#"