English|中文
Connect devices to the tKeel IoT Hub.
Go device sdk includes the following packages:
- client use paho.mqtt pub/sub mqtt msg
- spec provide message spec topics that communicate with the platform, you can find the spec here
- samples showing how to use the SDK
- Sends raw/telemetry/attribute message to IoT Hub.
- Recv raw/attribute/command message from IoT Hub
- Supports transport protocols: MQTT/MQTTs.
- Supports auto reconnect.
- Buffers data when the network connection is down.
API | Function |
---|---|
PublishRaw | publish raw message |
PublishTelemetry | publish telemetry message |
PublishAttribute | publish attribute message |
SubscribeRaw | subscribe raw message from IoT Hub |
SubscribeAttribute | subscribe attribute message from IoT Hub |
SubscribeCommand | subscribe raw command message from IoT Hub |
Connect | connect to IoT Hub |
Close | disconnect from IoT Hub |
NewClient | new client you can config enable tls,qos etc. |
Before use this sdk you'd better read this message spec here and assuming you already have installed Go
go get -u github.com/tkeel-io/device-sdk-go
import "github.com/tkeel-io/device-sdk-go"
// create default client
cli := client.NewClient(_brokerAddr, _username, _pwd)()
// connect to IoT Hub
cli.Connect()
// sub attribute
cli.SubscribeRaw(context.TODO(), rawTopicHandler)
// pub telemetry
cli.PublishTelemetry(ctx, v)
// close client
cli.Close()
// create a client enable tls
cli := client.NewClient(_brokerAddr, _username, _pwd)(
client.WithUseSSL(true),
client.WithServerCert("your cert file"))
Parameter | Description | Default |
---|---|---|
host | IoT Hub broker address | "" |
username | Device ID From IoT Hub | "" |
password | Device Token From IoT Hub | "" |
These params above must be set, if you want to enable tls or set qos etc. you can use Withxx func set when new client like client.WithQoS(1)