From 20148c35ee5a1ea39e28f161456ff8eaadb8204b Mon Sep 17 00:00:00 2001 From: Mirko Curtolo Date: Wed, 25 Jan 2023 11:36:54 +0100 Subject: [PATCH 1/2] Add opta support --- .github/workflows/sync-binaries-task.yml | 1 + command/device/board.go | 1 + command/ota/generate.go | 1 + firmware/generator.py | 1 + 4 files changed, 4 insertions(+) diff --git a/.github/workflows/sync-binaries-task.yml b/.github/workflows/sync-binaries-task.yml index ad2832a6..844e178c 100644 --- a/.github/workflows/sync-binaries-task.yml +++ b/.github/workflows/sync-binaries-task.yml @@ -27,6 +27,7 @@ jobs: arduino-cli core install arduino:mbed_nano arduino-cli core install arduino:mbed_portenta arduino-cli core install arduino:mbed_nicla + arduino-cli core install arduino:mbed_opta arduino-cli lib install ArduinoIotCloud arduino-cli lib install ArduinoECCX08 arduino-cli lib install ArduinoSTL diff --git a/command/device/board.go b/command/device/board.go index 1c76c7f1..6aa1c525 100644 --- a/command/device/board.go +++ b/command/device/board.go @@ -33,6 +33,7 @@ var ( "arduino:samd:mkr1000", "arduino:samd:mkrgsm1400", "arduino:samd:mkrnb1500", + "arduino:mbed_opta:opta", } loraFQBN = []string{ "arduino:samd:mkrwan1310", diff --git a/command/ota/generate.go b/command/ota/generate.go index 9dc507be..f2e6743f 100644 --- a/command/ota/generate.go +++ b/command/ota/generate.go @@ -37,6 +37,7 @@ var ( "arduino:mbed_nano:nanorp2040connect": "005E", "arduino:mbed_portenta:envie_m7": "025B", "arduino:mbed_nicla:nicla_vision": "025F", + "arduino:mbed_opta:opta": "0064", } ) diff --git a/firmware/generator.py b/firmware/generator.py index bd5050d9..ca87241d 100755 --- a/firmware/generator.py +++ b/firmware/generator.py @@ -29,6 +29,7 @@ {"type": "crypto", "ext": ".bin", "fqbn": "arduino:samd:mkr1000"}, {"type": "crypto", "ext": ".bin", "fqbn": "arduino:samd:mkrgsm1400"}, {"type": "crypto", "ext": ".bin", "fqbn": "arduino:samd:mkrnb1500"}, + {"type": "crypto", "ext": ".bin", "fqbn": "arduino:mbed_opta:opta"}, {"type": "lora", "ext": ".bin", "fqbn": "arduino:samd:mkrwan1300"}, {"type": "lora", "ext": ".bin", "fqbn": "arduino:samd:mkrwan1310"}, ] From 8afc3d45741c2baf2dd45edcf041c65bf256b413 Mon Sep 17 00:00:00 2001 From: Mirko Curtolo <47823364+mirkokurt@users.noreply.github.com> Date: Fri, 27 Jan 2023 10:06:02 +0100 Subject: [PATCH 2/2] Manage connection parameter for device create (#131) * Update the go client and manage connection parameter for device create --- .../go/github.com/arduino/iot-client-go.dep.yml | 2 +- README.md | 15 +++++++++++++++ cli/device/create.go | 11 ++++++++--- command/device/create.go | 9 +++++---- command/device/creategeneric.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- internal/iot/client.go | 10 ++++++++-- 8 files changed, 41 insertions(+), 14 deletions(-) diff --git a/.licenses/go/github.com/arduino/iot-client-go.dep.yml b/.licenses/go/github.com/arduino/iot-client-go.dep.yml index 1df2ad15..ae869df4 100644 --- a/.licenses/go/github.com/arduino/iot-client-go.dep.yml +++ b/.licenses/go/github.com/arduino/iot-client-go.dep.yml @@ -1,6 +1,6 @@ --- name: github.com/arduino/iot-client-go -version: v1.4.2 +version: v1.4.4 type: go summary: homepage: https://pkg.go.dev/github.com/arduino/iot-client-go diff --git a/README.md b/README.md index 1ade78b6..111cbcb7 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,21 @@ Here are the FQBNs of the Arduino boards that can be provisioned with this comma * `arduino:samd:mkrgsm1400` * `arduino:samd:mkrnb1500` +If the device supports more than one connectivity type (Eg: WiFi and Ethernet) the --connection flag can be used to set the desired connectivity + +```bash +arduino-cloud-cli device create --name --port --fqbn --connection +``` + +Here the list of available connection values: + +* `wifi` to set WiFi connectivity +* `eth` to set Ethernet connectivity +* `wifiandsecret` +* `gsm` to set Gsm connectivity +* `nb` to set Narrowband connectivity +* `lora` to set Lora connectivity + ### Devices with LoRaWAN connectivity LoRaWAN devices should be provisioned using a specific command. diff --git a/cli/device/create.go b/cli/device/create.go index 0c5aabc3..bca5453e 100644 --- a/cli/device/create.go +++ b/cli/device/create.go @@ -32,9 +32,10 @@ import ( ) type createFlags struct { - port string - name string - fqbn string + port string + name string + fqbn string + ctype string } func initCreateCommand() *cobra.Command { @@ -53,6 +54,7 @@ func initCreateCommand() *cobra.Command { createCommand.Flags().StringVarP(&flags.port, "port", "p", "", "Device port") createCommand.Flags().StringVarP(&flags.name, "name", "n", "", "Device name") createCommand.Flags().StringVarP(&flags.fqbn, "fqbn", "b", "", "Device fqbn") + createCommand.Flags().StringVarP(&flags.ctype, "connection", "c", "", "Device connection type") createCommand.MarkFlagRequired("name") return createCommand } @@ -68,6 +70,9 @@ func runCreateCommand(flags *createFlags) error { params := &device.CreateParams{ Name: flags.name, } + if flags.ctype != "" { + params.ConnectionType = &flags.ctype + } if flags.port != "" { params.Port = &flags.port } diff --git a/command/device/create.go b/command/device/create.go index d7741983..33d5cd30 100644 --- a/command/device/create.go +++ b/command/device/create.go @@ -31,9 +31,10 @@ import ( // CreateParams contains the parameters needed // to find the device to be provisioned. type CreateParams struct { - Name string // Device name - Port *string // Serial port - Optional - If omitted then each serial port is analyzed - FQBN *string // Board FQBN - Optional - If omitted then the first device found gets selected + Name string // Device name + Port *string // Serial port - Optional - If omitted then each serial port is analyzed + FQBN *string // Board FQBN - Optional - If omitted then the first device found gets selected + ConnectionType *string // Connection type - Optional - If omitted then the default connection type (depends on the board type) get selected } // Create command is used to provision a new arduino device @@ -70,7 +71,7 @@ func Create(ctx context.Context, params *CreateParams, cred *config.Credentials) } logrus.Info("Creating a new device on the cloud") - dev, err := iotClient.DeviceCreate(ctx, board.fqbn, params.Name, board.serial, board.dType) + dev, err := iotClient.DeviceCreate(ctx, board.fqbn, params.Name, board.serial, board.dType, params.ConnectionType) if err != nil { return nil, err } diff --git a/command/device/creategeneric.go b/command/device/creategeneric.go index 9d72c315..f0ebbe0b 100644 --- a/command/device/creategeneric.go +++ b/command/device/creategeneric.go @@ -50,7 +50,7 @@ func CreateGeneric(ctx context.Context, params *CreateGenericParams, cred *confi return nil, err } - dev, err := iotClient.DeviceCreate(ctx, params.FQBN, params.Name, "", genericDType) + dev, err := iotClient.DeviceCreate(ctx, params.FQBN, params.Name, "", genericDType, nil) if err != nil { return nil, err } diff --git a/go.mod b/go.mod index e6cc7a8c..831d3861 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/arduino/board-discovery v0.0.0-20211020061712-fd83c2e3c908 // indirect github.com/arduino/go-paths-helper v1.7.0 github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b - github.com/arduino/iot-client-go v1.4.2 + github.com/arduino/iot-client-go v1.4.4 github.com/gofrs/uuid v4.2.0+incompatible github.com/google/go-cmp v0.5.6 github.com/h2non/filetype v1.1.3 // indirect diff --git a/go.sum b/go.sum index e24e4eae..fd07bbd5 100644 --- a/go.sum +++ b/go.sum @@ -78,8 +78,8 @@ github.com/arduino/go-properties-orderedmap v1.7.1/go.mod h1:DKjD2VXY/NZmlingh4l github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b/go.mod h1:uwGy5PpN4lqW97FiLnbcx+xx8jly5YuPMJWfVwwjJiQ= github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b h1:3PjgYG5gVPA7cipp7vIR2lF96KkEJIFBJ+ANnuv6J20= github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b/go.mod h1:iIPnclBMYm1g32Q5kXoqng4jLhMStReIP7ZxaoUC2y8= -github.com/arduino/iot-client-go v1.4.2 h1:uZC8A26ytxSkuxNBFL2b/4w0TYjsR3ny2BbB5aVe4kw= -github.com/arduino/iot-client-go v1.4.2/go.mod h1:gYvpMt7Qw+OSScTLyIlCnpbvy9y96ey/2zhB4w6FoK0= +github.com/arduino/iot-client-go v1.4.4 h1:FICCXD5uCZ0scGG6RioOlpZamDqgSD1l/fQlFwKR284= +github.com/arduino/iot-client-go v1.4.4/go.mod h1:gYvpMt7Qw+OSScTLyIlCnpbvy9y96ey/2zhB4w6FoK0= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-metrics v0.3.10/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc= diff --git a/internal/iot/client.go b/internal/iot/client.go index b5beab33..3a438b27 100644 --- a/internal/iot/client.go +++ b/internal/iot/client.go @@ -48,7 +48,7 @@ func NewClient(cred *config.Credentials) (*Client, error) { // DeviceCreate allows to create a new device on Arduino IoT Cloud. // It returns the newly created device, and an error. -func (cl *Client) DeviceCreate(ctx context.Context, fqbn, name, serial, dType string) (*iotclient.ArduinoDevicev2, error) { +func (cl *Client) DeviceCreate(ctx context.Context, fqbn, name, serial, dType string, cType *string) (*iotclient.ArduinoDevicev2, error) { ctx, err := ctxWithToken(ctx, cl.token) if err != nil { return nil, err @@ -60,6 +60,11 @@ func (cl *Client) DeviceCreate(ctx context.Context, fqbn, name, serial, dType st Serial: serial, Type: dType, } + + if cType != nil { + payload.ConnectionType = *cType + } + dev, _, err := cl.api.DevicesV2Api.DevicesV2Create(ctx, payload, nil) if err != nil { err = fmt.Errorf("creating device, %w", errorDetail(err)) @@ -85,7 +90,8 @@ func (cl *Client) DeviceLoraCreate(ctx context.Context, name, serial, devType, e Type: devType, UserId: "me", } - dev, _, err := cl.api.LoraDevicesV1Api.LoraDevicesV1Create(ctx, payload) + + dev, _, err := cl.api.LoraDevicesV1Api.LoraDevicesV1Create(ctx, payload, nil) if err != nil { err = fmt.Errorf("creating lora device: %w", errorDetail(err)) return nil, err