|
|
@@ -11,12 +11,13 @@ import (
|
|
|
)
|
|
|
|
|
|
type MqttClientOptions struct {
|
|
|
- UserName string
|
|
|
- Password string
|
|
|
- Address string
|
|
|
- ClientID string
|
|
|
- KeepAliveSec time.Duration
|
|
|
- PingTimeoutSec time.Duration
|
|
|
+ UserName string
|
|
|
+ Password string
|
|
|
+ Address string
|
|
|
+ ClientID string
|
|
|
+ KeepAliveSec time.Duration
|
|
|
+ PingTimeoutSec time.Duration
|
|
|
+ WriteTimeoutSec time.Duration
|
|
|
}
|
|
|
|
|
|
func (opt *MqttClientOptions) check() error {
|
|
|
@@ -69,6 +70,7 @@ func NewMqttClient(opts *MqttClientOptions) (*MqttClient, error) {
|
|
|
SetClientID(opts.ClientID).
|
|
|
SetKeepAlive(opts.KeepAliveSec*time.Second).
|
|
|
SetPingTimeout(opts.PingTimeoutSec*time.Second).
|
|
|
+ SetWriteTimeout(opts.WriteTimeoutSec*time.Second).
|
|
|
SetWill(opts.ClientID+"/will", "dead", 2, false).
|
|
|
SetOnConnectHandler(func(client mqtt.Client) {
|
|
|
err := mqttClient.onConnect()
|