@@ -3,6 +3,7 @@ package iot
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "os"
6
7
7
8
"github.com/antihax/optional"
8
9
iotclient "github.com/arduino/iot-client-go"
@@ -14,6 +15,7 @@ type Client interface {
14
15
DeviceDelete (id string ) error
15
16
DeviceList () ([]iotclient.ArduinoDevicev2 , error )
16
17
DeviceShow (id string ) (* iotclient.ArduinoDevicev2 , error )
18
+ DeviceOTA (id string , file * os.File ) error
17
19
CertificateCreate (id , csr string ) (* iotclient.ArduinoCompressedv2 , error )
18
20
ThingCreate (thing * iotclient.Thing , force bool ) (string , error )
19
21
ThingUpdate (id string , thing * iotclient.Thing , force bool ) error
@@ -89,6 +91,20 @@ func (cl *client) DeviceShow(id string) (*iotclient.ArduinoDevicev2, error) {
89
91
return & dev , nil
90
92
}
91
93
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
+
92
108
// CertificateCreate allows to upload a certificate on Arduino IoT Cloud.
93
109
// It returns the certificate parameters populated by the cloud.
94
110
func (cl * client ) CertificateCreate (id , csr string ) (* iotclient.ArduinoCompressedv2 , error ) {
0 commit comments