Skip to content

Commit c6ad6c9

Browse files
committed
first mass upload draft script
1 parent d0950a5 commit c6ad6c9

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

tools/ota/ota_mass_upload.sh

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# !/bin/bash
2+
3+
# This script is used to upload the firmware to the device using the OTA service.
4+
5+
export PATH=$PATH:.
6+
7+
checkExecutable () {
8+
if ! command -v $1 &> /dev/null
9+
then
10+
echo "$1 could not be found in PATH"
11+
exit 1
12+
fi
13+
}
14+
15+
# Check dependencies...
16+
checkExecutable "arduino-cloud-cli"
17+
checkExecutable "jq"
18+
checkExecutable "sort"
19+
checkExecutable "uniq"
20+
21+
# Default wait time for OTA process to complete
22+
waittime=600
23+
24+
while getopts t:v:f:o: flag
25+
do
26+
case "${flag}" in
27+
t) tag=${OPTARG};;
28+
v) version=${OPTARG};;
29+
f) firmwarefile=${OPTARG};;
30+
o) waittime=${OPTARG};;
31+
esac
32+
done
33+
34+
echo "Starting OTA process for devices with tag \"$tag\" using firmware \"$firmwarefile\""
35+
echo ""
36+
37+
devicelistjson=$(arduino-cloud-cli device list --tags $tag --format json)
38+
devicecount=$(echo $devicelistjson | jq '.[] | .id' | wc -l)
39+
40+
if [ "$devicecount" -gt 0 ]; then
41+
echo "Found $devicecount devices with tag \"$tag\""
42+
echo ""
43+
arduino-cloud-cli device list --tags $tag
44+
else
45+
echo "No devices found with tag \"$tag\""
46+
exit 1
47+
fi
48+
49+
fqbncount=$(echo $devicelistjson | jq '.[] | .fqbn' | sort | uniq | wc -l)
50+
51+
if [ "$fqbncount" -gt 1 ]; then
52+
echo "Mixed FQBNs detected. Please ensure all devices have the same FQBN."
53+
fqbns=$(echo $devicelistjson | jq '.[] | .fqbn' | sort | uniq)
54+
echo "Detected FQBNs: $fqbns"
55+
exit 1
56+
fi
57+
58+
fqbn=$(echo $devicelistjson | jq -r '.[] | .fqbn' | sort | uniq | head -n 1)
59+
60+
otastartedout=$(arduino-cloud-cli ota mass-upload --device-tags $tag --file $firmwarefile -b $fqbn --format json)
61+
if [ $? -ne 0 ]; then
62+
echo "Detected error during OTA process. Exiting..."
63+
exit 1
64+
fi
65+
66+
otaids=$(echo $otastartedout | jq -r '.[] | .OtaStatus | .id' | uniq | paste -sd "," -)
67+
68+
echo "IDS: $otaids"
69+
70+
while [ $waittime -gt 0 ]; do
71+
echo "Waiting for $waittime seconds for OTA process to complete..."
72+
sleep 15
73+
waittime=$((waittime-15))
74+
done
75+
76+
exit 0

0 commit comments

Comments
 (0)