Skip to content

Commit 8afc3d4

Browse files
committed
Manage connection parameter for device create (#131)
* Update the go client and manage connection parameter for device create
1 parent 20148c3 commit 8afc3d4

File tree

8 files changed

+41
-14
lines changed

8 files changed

+41
-14
lines changed

Diff for: .licenses/go/github.com/arduino/iot-client-go.dep.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: github.com/arduino/iot-client-go
3-
version: v1.4.2
3+
version: v1.4.4
44
type: go
55
summary:
66
homepage: https://pkg.go.dev/github.com/arduino/iot-client-go

Diff for: README.md

+15
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,21 @@ Here are the FQBNs of the Arduino boards that can be provisioned with this comma
110110
* `arduino:samd:mkrgsm1400`
111111
* `arduino:samd:mkrnb1500`
112112

113+
If the device supports more than one connectivity type (Eg: WiFi and Ethernet) the --connection flag can be used to set the desired connectivity
114+
115+
```bash
116+
arduino-cloud-cli device create --name <deviceName> --port <port> --fqbn <deviceFqbn> --connection <deviceConnectivity>
117+
```
118+
119+
Here the list of available connection values:
120+
121+
* `wifi` to set WiFi connectivity
122+
* `eth` to set Ethernet connectivity
123+
* `wifiandsecret`
124+
* `gsm` to set Gsm connectivity
125+
* `nb` to set Narrowband connectivity
126+
* `lora` to set Lora connectivity
127+
113128
### Devices with LoRaWAN connectivity
114129

115130
LoRaWAN devices should be provisioned using a specific command.

Diff for: cli/device/create.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ import (
3232
)
3333

3434
type createFlags struct {
35-
port string
36-
name string
37-
fqbn string
35+
port string
36+
name string
37+
fqbn string
38+
ctype string
3839
}
3940

4041
func initCreateCommand() *cobra.Command {
@@ -53,6 +54,7 @@ func initCreateCommand() *cobra.Command {
5354
createCommand.Flags().StringVarP(&flags.port, "port", "p", "", "Device port")
5455
createCommand.Flags().StringVarP(&flags.name, "name", "n", "", "Device name")
5556
createCommand.Flags().StringVarP(&flags.fqbn, "fqbn", "b", "", "Device fqbn")
57+
createCommand.Flags().StringVarP(&flags.ctype, "connection", "c", "", "Device connection type")
5658
createCommand.MarkFlagRequired("name")
5759
return createCommand
5860
}
@@ -68,6 +70,9 @@ func runCreateCommand(flags *createFlags) error {
6870
params := &device.CreateParams{
6971
Name: flags.name,
7072
}
73+
if flags.ctype != "" {
74+
params.ConnectionType = &flags.ctype
75+
}
7176
if flags.port != "" {
7277
params.Port = &flags.port
7378
}

Diff for: command/device/create.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ import (
3131
// CreateParams contains the parameters needed
3232
// to find the device to be provisioned.
3333
type CreateParams struct {
34-
Name string // Device name
35-
Port *string // Serial port - Optional - If omitted then each serial port is analyzed
36-
FQBN *string // Board FQBN - Optional - If omitted then the first device found gets selected
34+
Name string // Device name
35+
Port *string // Serial port - Optional - If omitted then each serial port is analyzed
36+
FQBN *string // Board FQBN - Optional - If omitted then the first device found gets selected
37+
ConnectionType *string // Connection type - Optional - If omitted then the default connection type (depends on the board type) get selected
3738
}
3839

3940
// Create command is used to provision a new arduino device
@@ -70,7 +71,7 @@ func Create(ctx context.Context, params *CreateParams, cred *config.Credentials)
7071
}
7172

7273
logrus.Info("Creating a new device on the cloud")
73-
dev, err := iotClient.DeviceCreate(ctx, board.fqbn, params.Name, board.serial, board.dType)
74+
dev, err := iotClient.DeviceCreate(ctx, board.fqbn, params.Name, board.serial, board.dType, params.ConnectionType)
7475
if err != nil {
7576
return nil, err
7677
}

Diff for: command/device/creategeneric.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func CreateGeneric(ctx context.Context, params *CreateGenericParams, cred *confi
5050
return nil, err
5151
}
5252

53-
dev, err := iotClient.DeviceCreate(ctx, params.FQBN, params.Name, "", genericDType)
53+
dev, err := iotClient.DeviceCreate(ctx, params.FQBN, params.Name, "", genericDType, nil)
5454
if err != nil {
5555
return nil, err
5656
}

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/arduino/board-discovery v0.0.0-20211020061712-fd83c2e3c908 // indirect
1010
github.com/arduino/go-paths-helper v1.7.0
1111
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b
12-
github.com/arduino/iot-client-go v1.4.2
12+
github.com/arduino/iot-client-go v1.4.4
1313
github.com/gofrs/uuid v4.2.0+incompatible
1414
github.com/google/go-cmp v0.5.6
1515
github.com/h2non/filetype v1.1.3 // indirect

Diff for: go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ github.com/arduino/go-properties-orderedmap v1.7.1/go.mod h1:DKjD2VXY/NZmlingh4l
7878
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b/go.mod h1:uwGy5PpN4lqW97FiLnbcx+xx8jly5YuPMJWfVwwjJiQ=
7979
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b h1:3PjgYG5gVPA7cipp7vIR2lF96KkEJIFBJ+ANnuv6J20=
8080
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b/go.mod h1:iIPnclBMYm1g32Q5kXoqng4jLhMStReIP7ZxaoUC2y8=
81-
github.com/arduino/iot-client-go v1.4.2 h1:uZC8A26ytxSkuxNBFL2b/4w0TYjsR3ny2BbB5aVe4kw=
82-
github.com/arduino/iot-client-go v1.4.2/go.mod h1:gYvpMt7Qw+OSScTLyIlCnpbvy9y96ey/2zhB4w6FoK0=
81+
github.com/arduino/iot-client-go v1.4.4 h1:FICCXD5uCZ0scGG6RioOlpZamDqgSD1l/fQlFwKR284=
82+
github.com/arduino/iot-client-go v1.4.4/go.mod h1:gYvpMt7Qw+OSScTLyIlCnpbvy9y96ey/2zhB4w6FoK0=
8383
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
8484
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
8585
github.com/armon/go-metrics v0.3.10/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc=

Diff for: internal/iot/client.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func NewClient(cred *config.Credentials) (*Client, error) {
4848

4949
// DeviceCreate allows to create a new device on Arduino IoT Cloud.
5050
// It returns the newly created device, and an error.
51-
func (cl *Client) DeviceCreate(ctx context.Context, fqbn, name, serial, dType string) (*iotclient.ArduinoDevicev2, error) {
51+
func (cl *Client) DeviceCreate(ctx context.Context, fqbn, name, serial, dType string, cType *string) (*iotclient.ArduinoDevicev2, error) {
5252
ctx, err := ctxWithToken(ctx, cl.token)
5353
if err != nil {
5454
return nil, err
@@ -60,6 +60,11 @@ func (cl *Client) DeviceCreate(ctx context.Context, fqbn, name, serial, dType st
6060
Serial: serial,
6161
Type: dType,
6262
}
63+
64+
if cType != nil {
65+
payload.ConnectionType = *cType
66+
}
67+
6368
dev, _, err := cl.api.DevicesV2Api.DevicesV2Create(ctx, payload, nil)
6469
if err != nil {
6570
err = fmt.Errorf("creating device, %w", errorDetail(err))
@@ -85,7 +90,8 @@ func (cl *Client) DeviceLoraCreate(ctx context.Context, name, serial, devType, e
8590
Type: devType,
8691
UserId: "me",
8792
}
88-
dev, _, err := cl.api.LoraDevicesV1Api.LoraDevicesV1Create(ctx, payload)
93+
94+
dev, _, err := cl.api.LoraDevicesV1Api.LoraDevicesV1Create(ctx, payload, nil)
8995
if err != nil {
9096
err = fmt.Errorf("creating lora device: %w", errorDetail(err))
9197
return nil, err

0 commit comments

Comments
 (0)