Skip to content

Commit 03d471b

Browse files
committed
Add deferred option
1 parent 4f5b32e commit 03d471b

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

cli/ota/upload.go

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
var uploadFlags struct {
1111
deviceID string
1212
file string
13+
deferred bool
1314
}
1415

1516
func initUploadCommand() *cobra.Command {
@@ -22,6 +23,7 @@ func initUploadCommand() *cobra.Command {
2223

2324
uploadCommand.Flags().StringVarP(&uploadFlags.deviceID, "device-id", "d", "", "Device ID")
2425
uploadCommand.Flags().StringVarP(&uploadFlags.file, "file", "", "", "Binary file (.bin) to be uploaded")
26+
uploadCommand.Flags().BoolVar(&uploadFlags.deferred, "deferred", false, "Perform a deferred OTA. It can take up to 1 week.")
2527

2628
uploadCommand.MarkFlagRequired("device-id")
2729
uploadCommand.MarkFlagRequired("file")

command/ota/upload.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@ import (
1010
"github.com/arduino/iot-cloud-cli/internal/iot"
1111
)
1212

13+
const (
14+
otaExpirationMins = 10
15+
otaDeferredExpirationMins = 10000
16+
)
17+
1318
// UploadParams contains the parameters needed to
1419
// perform an OTA upload.
1520
type UploadParams struct {
1621
DeviceID string
1722
File string
23+
Deferred bool
1824
}
1925

2026
// Upload command is used to upload a firmware OTA,
@@ -51,7 +57,12 @@ func Upload(params *UploadParams) error {
5157
return fmt.Errorf("%s: %w", "cannot open ota file", err)
5258
}
5359

54-
err = iotClient.DeviceOTA(params.DeviceID, file)
60+
expiration := otaExpirationMins
61+
if params.Deferred {
62+
expiration = otaDeferredExpirationMins
63+
}
64+
65+
err = iotClient.DeviceOTA(params.DeviceID, file, expiration)
5566
if err != nil {
5667
return err
5768
}

internal/iot/client.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type Client interface {
1515
DeviceDelete(id string) error
1616
DeviceList() ([]iotclient.ArduinoDevicev2, error)
1717
DeviceShow(id string) (*iotclient.ArduinoDevicev2, error)
18-
DeviceOTA(id string, file *os.File) error
18+
DeviceOTA(id string, file *os.File, expireMins int) error
1919
CertificateCreate(id, csr string) (*iotclient.ArduinoCompressedv2, error)
2020
ThingCreate(thing *iotclient.Thing, force bool) (string, error)
2121
ThingUpdate(id string, thing *iotclient.Thing, force bool) error
@@ -93,9 +93,9 @@ func (cl *client) DeviceShow(id string) (*iotclient.ArduinoDevicev2, error) {
9393

9494
// DeviceOTA performs an OTA upload request to Arduino IoT Cloud, passing
9595
// the ID of the device to be updated and the actual file containing the OTA firmware.
96-
func (cl *client) DeviceOTA(id string, file *os.File) error {
96+
func (cl *client) DeviceOTA(id string, file *os.File, expireMins int) error {
9797
opt := &iotclient.DevicesV2OtaUploadOpts{
98-
ExpireInMins: optional.NewInt32(5),
98+
ExpireInMins: optional.NewInt32(int32(expireMins)),
9999
}
100100
_, err := cl.api.DevicesV2OtaApi.DevicesV2OtaUpload(cl.ctx, id, file, opt)
101101
if err != nil {

0 commit comments

Comments
 (0)