func (t *thing) Disconnect(ctx context.Context) {
	if t.client != nil {
		t.client.Unsubscribe(ctx, t.configTopic())
		if t.client.IsConnected() {
			t.infof("Disconnecting")
			t.client.Disconnect(ctx)
		}
	}
}
Disconnect from the MQTT server(s)
package iot
import (
	"context"
	"fmt"
	"strings"
	"time"
	"github.com/benbjohnson/clock"
	"github.com/dgrijalva/jwt-go"
)
type thing struct {
	options       *ThingOptions
	client        MQTTClient
	publishTicker *clock.Ticker
}
func (t *thing) PublishState(ctx context.Context, message []byte) error {
	return t.publish(ctx, t.stateTopic(), message, t.options.StateQOS)
}
func (t *thing) PublishEvent(ctx context.Context, message []byte, event ...string) error {
	return t.publish(ctx, t.eventsTopic(event...), message, t.options.EventQOS)
}
func (t *thing) Connect(ctx context.Context, servers ...string) error {
	if t.IsConnected() {
		return nil
	}
	if t.options.ID == nil || t.options.Credentials == nil {
		return ErrConfigurationError
	}
	if t.options.AuthTokenExpiration == 0 {
		t.options.AuthTokenExpiration = DefaultAuthTokenExpiration
	}
	if t.options.Clock == nil {
		t.options.Clock = clock.New()
	}
	if NewClient == nil {
		panic("No MQTT client specified. Please import the iot/paho package.")
	}
	t.client = NewClient(t, t.options)
	if t.options.LogMQTT {
		t.client.SetDebugLogger(t.options.DebugLogger)
		t.client.SetInfoLogger(t.options.InfoLogger)
		t.client.SetErrorLogger(t.options.ErrorLogger)
	}
	t.client.SetClientID(t.clientID())
	t.publishTicker = t.options.Clock.Ticker(time.Second * 2)
	t.client.SetCredentialsProvider(func() (username string, password string) {
		authToken, err := t.authToken()
		if err != nil {
			t.errorf("Error generating auth token: %v", err)
			return "", ""
		}
		return "unused", authToken
	})
	t.client.SetOnConnectHandler(func(client MQTTClient) {
		client.Subscribe(ctx, t.configTopic(), t.options.ConfigQOS, t.options.ConfigHandler)
	})
	err := t.client.Connect(ctx, servers...)
	if err != nil {
		return err
	}
	return err
}
func (t *thing) IsConnected() bool {
	return t.client != nil && t.client.IsConnected()
}