@@ -21,6 +21,7 @@ import (
21
21
"context"
22
22
"errors"
23
23
"fmt"
24
+ "github.com/sirupsen/logrus"
24
25
"os"
25
26
"path/filepath"
26
27
@@ -54,6 +55,27 @@ type Result struct {
54
55
OtaStatus otaapi.Ota
55
56
}
56
57
58
+ func buildOtaFile (params * MassUploadParams ) (string , string , error ) {
59
+ var otaFile string
60
+ var otaDir string
61
+ var err error
62
+ if params .DoNotApplyHeader {
63
+ otaFile = params .File
64
+ } else {
65
+ otaDir , err = os .MkdirTemp ("" , "" )
66
+ if err != nil {
67
+ return "" , "" , fmt .Errorf ("%s: %w" , "cannot create temporary folder" , err )
68
+ }
69
+ otaFile = filepath .Join (otaDir , "temp.ota" )
70
+
71
+ err = Generate (params .File , otaFile , params .FQBN )
72
+ if err != nil {
73
+ return "" , "" , fmt .Errorf ("%s: %w" , "cannot generate .ota file" , err )
74
+ }
75
+ }
76
+ return otaFile , otaDir , nil
77
+ }
78
+
57
79
// MassUpload command is used to mass upload a firmware OTA,
58
80
// on devices of Arduino IoT Cloud.
59
81
func MassUpload (ctx context.Context , params * MassUploadParams , cred * config.Credentials ) ([]Result , error ) {
@@ -64,6 +86,7 @@ func MassUpload(ctx context.Context, params *MassUploadParams, cred *config.Cred
64
86
}
65
87
66
88
// Generate .ota file
89
+ logrus .Infoln ("Uploading binary" , params .File )
67
90
_ , err := os .Stat (params .File )
68
91
if err != nil {
69
92
return nil , fmt .Errorf ("file %s does not exists: %w" , params .File , err )
@@ -78,21 +101,12 @@ func MassUpload(ctx context.Context, params *MassUploadParams, cred *config.Cred
78
101
}
79
102
80
103
// Generate .ota file
81
- var otaFile string
82
- if params .DoNotApplyHeader {
83
- otaFile = params .File
84
- } else {
85
- otaDir , err := os .MkdirTemp ("" , "" )
86
- if err != nil {
87
- return nil , fmt .Errorf ("%s: %w" , "cannot create temporary folder" , err )
88
- }
89
- otaFile := filepath .Join (otaDir , "temp.ota" )
104
+ otaFile , otaDir , err := buildOtaFile (params )
105
+ if err != nil {
106
+ return nil , err
107
+ }
108
+ if otaDir != "" {
90
109
defer os .RemoveAll (otaDir )
91
-
92
- err = Generate (params .File , otaFile , params .FQBN )
93
- if err != nil {
94
- return nil , fmt .Errorf ("%s: %w" , "cannot generate .ota file" , err )
95
- }
96
110
}
97
111
98
112
iotClient , err := iot .NewClient (cred )
@@ -196,6 +210,7 @@ func run(ctx context.Context, uploader otaUploader, otapi otaStatusGetter, ids [
196
210
for _ , id := range ids {
197
211
file , err := os .Open (otaFile )
198
212
if err != nil {
213
+ logrus .Error ("cannot open ota file:" , otaFile )
199
214
r := Result {ID : id , Err : fmt .Errorf ("cannot open ota file" )}
200
215
results = append (results , r )
201
216
continue
@@ -205,6 +220,7 @@ func run(ctx context.Context, uploader otaUploader, otapi otaStatusGetter, ids [
205
220
}
206
221
close (jobs )
207
222
223
+ logrus .Infoln ("Uploading firmware to devices..." )
208
224
for i := 0 ; i < numConcurrentUploads ; i ++ {
209
225
go func () {
210
226
for job := range jobs {
0 commit comments