File tree Expand file tree Collapse file tree 3 files changed +11
-11
lines changed Expand file tree Collapse file tree 3 files changed +11
-11
lines changed Original file line number Diff line number Diff line change @@ -25,13 +25,13 @@ This tool can be used to extend (actually prefix) a binary generated with e.g. t
25
25
0000030 0000 0000 7485 0000 0000 0000 0000 0000
26
26
```
27
27
28
- ` bin2base64 .py`
29
- ===============
30
- This tool converts the binary file into base64 encoding which is necessary for feeding it to the server.
28
+ ` bin2json .py`
29
+ =============
30
+ This tool converts the binary file into base64 encoded JSON which is necessary for feeding it to the server.
31
31
32
32
### How-To-Use
33
33
``` bash
34
- ./bin2base64 .py sketch-ota.bin sketch-ota.base64
34
+ ./bin2json .py sketch-ota.bin sketch-ota.json
35
35
```
36
36
37
37
` ota-upload.sh `
@@ -40,5 +40,5 @@ This tool allows to upload a OTA binary to a device via a Arduino cloud server.
40
40
41
41
### How-To-Use
42
42
``` bash
43
- ./ota-upload.sh CLIENT_ID CLIENT_SECRET DEVICE_ID sketch-ota.base64
43
+ ./ota-upload.sh CLIENT_ID CLIENT_SECRET DEVICE_ID sketch-ota.json
44
44
```
Original file line number Diff line number Diff line change 1
1
#!/usr/bin/python3
2
2
3
3
import sys
4
+ import json
4
5
import base64
5
6
6
7
if len (sys .argv ) != 3 :
7
- print ("Usage: bin2base64 .py sketch-ota.bin sketch-ota.base64 " )
8
+ print ("Usage: bin2json .py sketch-ota.bin sketch-ota.json " )
8
9
sys .exit ()
9
10
10
11
ifile = sys .argv [1 ]
11
12
ofile = sys .argv [2 ]
12
13
13
14
# Read the binary file
14
15
in_file = open (ifile , "rb" )
15
- bin_data = bytearray ( in_file .read () )
16
+ bin_data = in_file .read ()
16
17
in_file .close ()
17
18
18
19
# Perform the base64 conversion
19
20
base64_data = base64 .b64encode (bin_data )
20
21
21
22
# Write to outfile
22
- out_file = open (ofile , "wb " )
23
- out_file . write ( base64_data )
23
+ out_file = open (ofile , "w " )
24
+ json . dump ({ 'binary' : base64_data . decode ( "ascii" )}, out_file )
24
25
out_file .close ()
Original file line number Diff line number Diff line change 23
23
24
24
printf " Uploading to device ... "
25
25
access_token_val=$( < access_token)
26
- base64_binary=$( < " $4 " )
27
26
curl --silent --location --request PUT ' https://api-dev.arduino.cc/iot/v2/devices/' " $3 " ' /ota' \
28
27
--header ' Content-Type: application/json' \
29
28
--header ' Authorization: Bearer ' " $access_token_val " \
30
29
--header ' Content-Type: text/plain' \
31
- --data-raw ' {"binary":"base64encodedbinary"} '
30
+ -d @ " $4 "
32
31
echo " OK"
33
32
34
33
printf " Cleaning up ... "
You can’t perform that action at this time.
0 commit comments