Skip to content

Commit 051b323

Browse files
committed
Renaming bin2base64.py to bin2json.py in order to directly create a json object containing the base64 encoded binary because otherwise the URL becomes to long for curl to process
1 parent 9d71e95 commit 051b323

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

extras/tools/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ This tool can be used to extend (actually prefix) a binary generated with e.g. t
2525
0000030 0000 0000 7485 0000 0000 0000 0000 0000
2626
```
2727

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.
3131

3232
### How-To-Use
3333
```bash
34-
./bin2base64.py sketch-ota.bin sketch-ota.base64
34+
./bin2json.py sketch-ota.bin sketch-ota.json
3535
```
3636

3737
`ota-upload.sh`
@@ -40,5 +40,5 @@ This tool allows to upload a OTA binary to a device via a Arduino cloud server.
4040

4141
### How-To-Use
4242
```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
4444
```
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
#!/usr/bin/python3
22

33
import sys
4+
import json
45
import base64
56

67
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")
89
sys.exit()
910

1011
ifile = sys.argv[1]
1112
ofile = sys.argv[2]
1213

1314
# Read the binary file
1415
in_file = open(ifile, "rb")
15-
bin_data = bytearray(in_file.read())
16+
bin_data = in_file.read()
1617
in_file.close()
1718

1819
# Perform the base64 conversion
1920
base64_data = base64.b64encode(bin_data)
2021

2122
# 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)
2425
out_file.close()

extras/tools/ota-upload.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ fi
2323

2424
printf "Uploading to device ... "
2525
access_token_val=$(<access_token)
26-
base64_binary=$(<"$4")
2726
curl --silent --location --request PUT 'https://api-dev.arduino.cc/iot/v2/devices/'"$3"'/ota' \
2827
--header 'Content-Type: application/json' \
2928
--header 'Authorization: Bearer '"$access_token_val" \
3029
--header 'Content-Type: text/plain' \
31-
--data-raw '{"binary":"base64encodedbinary"}'
30+
-d @"$4"
3231
echo "OK"
3332

3433
printf "Cleaning up ... "

0 commit comments

Comments
 (0)