-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbind.go
38 lines (32 loc) · 811 Bytes
/
bind.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package thing
import (
iotclient "github.com/arduino/iot-client-go"
"github.com/arduino/iot-cloud-cli/internal/config"
"github.com/arduino/iot-cloud-cli/internal/iot"
)
// BindParams contains the parameters needed to
// bind a thing to a device.
type BindParams struct {
ID string // ID of the thing to be bound
DeviceID string // ID of the device to be bound
}
// Bind command is used to bind a thing to a device
// on Arduino IoT Cloud.
func Bind(params *BindParams) error {
conf, err := config.Retrieve()
if err != nil {
return err
}
iotClient, err := iot.NewClient(conf.Client, conf.Secret)
if err != nil {
return err
}
thing := &iotclient.Thing{
DeviceId: params.DeviceID,
}
err = iotClient.ThingUpdate(params.ID, thing, true)
if err != nil {
return err
}
return nil
}