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