@@ -3,6 +3,7 @@ package iot
33import (
44 "context"
55 "fmt"
6+ "os"
67
78 "github.com/antihax/optional"
89 iotclient "github.com/arduino/iot-client-go"
@@ -14,6 +15,7 @@ type Client interface {
1415 DeviceDelete (id string ) error
1516 DeviceList () ([]iotclient.ArduinoDevicev2 , error )
1617 DeviceShow (id string ) (* iotclient.ArduinoDevicev2 , error )
18+ DeviceOTA (id string , file * os.File ) error
1719 CertificateCreate (id , csr string ) (* iotclient.ArduinoCompressedv2 , error )
1820 ThingCreate (thing * iotclient.Thing , force bool ) (string , error )
1921 ThingUpdate (id string , thing * iotclient.Thing , force bool ) error
@@ -89,6 +91,20 @@ func (cl *client) DeviceShow(id string) (*iotclient.ArduinoDevicev2, error) {
8991 return & dev , nil
9092}
9193
94+ // DeviceOTA performs an OTA upload request to Arduino IoT Cloud, passing
95+ // 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 {
97+ opt := & iotclient.DevicesV2OtaUploadOpts {
98+ ExpireInMins : optional .NewInt32 (5 ),
99+ }
100+ _ , err := cl .api .DevicesV2OtaApi .DevicesV2OtaUpload (cl .ctx , id , file , opt )
101+ if err != nil {
102+ err = fmt .Errorf ("listing devices: %w" , errorDetail (err ))
103+ return err
104+ }
105+ return nil
106+ }
107+
92108// CertificateCreate allows to upload a certificate on Arduino IoT Cloud.
93109// It returns the certificate parameters populated by the cloud.
94110func (cl * client ) CertificateCreate (id , csr string ) (* iotclient.ArduinoCompressedv2 , error ) {
0 commit comments