I'm new in both GO and MQTT. After I started the client c := MQTT.NewClient(opts) c.Start() and until it disconnected each 30 sec. handshake traffic between client and broker showed up. I just need to adjust this interval or cancel handshake at all.
The keepAlive 'handshake' is required it can not be disabled, it is how the broker knows the client is still connected.
You can change the keepalive timeout by calling SetKeepAlive on the opts object before passing it to the NewClient method.
This method takes a value in seconds for the time between each keepAlive packet.
Using the sample code here, you would add a line like this to set the KeepAlive timeout to 30 seconds.
...
opts := MQTT.NewClientOptions().SetBroker("tcp://iot.eclipse.org:1883")
opts.SetClientId("go-simple")
opts.SetTraceLevel(MQTT.Off)
opts.SetDefaultPublishHandler(f)
opts.SetKeepAlive(30)
//create and start a client using the above ClientOptions
c := MQTT.NewClient(opts)
_, err := c.Start()
if err != nil {
panic(err)
}
...