2024-06-15 01:02:44 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
|
2024-06-15 04:34:32 +02:00
|
|
|
test -z $TTY && TTY="/dev/ttyUSB0"
|
2024-12-09 00:07:43 +01:00
|
|
|
test -z $IP && IP="192.168.4.20"
|
|
|
|
test -z $VER && VER="0.1.0"
|
2024-06-16 19:40:41 +02:00
|
|
|
BUILD="$(git rev-parse --short HEAD)-$(date '+%Y%m%d%H%M%S')"
|
2024-06-15 01:02:44 +02:00
|
|
|
|
2024-06-15 23:59:00 +02:00
|
|
|
ACLI="$HOME/.local/bin/arduino-cli"
|
|
|
|
ACLI_CMD="$ACLI --config-file arduino-cli.yml"
|
2024-09-14 15:57:14 +02:00
|
|
|
BOARD="esp8266:esp8266:d1_mini_clone"
|
2024-06-15 23:59:00 +02:00
|
|
|
|
2024-06-15 01:02:44 +02:00
|
|
|
function help() {
|
2024-06-15 23:59:00 +02:00
|
|
|
echo "$0 [setup|build|upload|webupload|monitor]"
|
2024-06-16 00:02:34 +02:00
|
|
|
echo "setup: setup build environment, download arduino-cli, install all dependencies for arduino ide"
|
|
|
|
echo "build: build firmware binary. will be saved into build/"
|
|
|
|
echo "upload: upload firmware by serial connection $TTY"
|
|
|
|
echo "webupload: upload firmware with webupload to $IP"
|
|
|
|
echo "monitor: serial monitor $TTY"
|
2024-06-15 01:02:44 +02:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2024-06-15 23:59:00 +02:00
|
|
|
function check_acli() {
|
|
|
|
if [ ! -x $ACLI ]
|
|
|
|
then
|
|
|
|
echo "$ACLI does not exist nor is executable. Please run '$0 setup' first"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-06-15 01:02:44 +02:00
|
|
|
test -z $1 && help
|
|
|
|
|
|
|
|
case $1 in
|
2024-06-15 23:59:00 +02:00
|
|
|
s|setup)
|
|
|
|
ACLI_DIR="$(dirname $ACLI)"
|
2024-12-08 23:45:47 +01:00
|
|
|
declare -a LIBS=( "Adafruit SSD1306" "Adafruit BME280 Library" "ArduinoJson" "NTPClient" "Time" "Adafruit SHT31 Library" )
|
2024-06-15 23:59:00 +02:00
|
|
|
echo ":: Setting up build environment for CanGrow Firmware."
|
|
|
|
echo " This will download the binary for arduino-cli and install"
|
|
|
|
echo " the packages for the arduino ide from the debian repository."
|
2024-06-16 00:03:38 +02:00
|
|
|
echo " !! This script is meant to be executed on a Debian stable (bookworm) system !!"
|
2024-06-15 23:59:00 +02:00
|
|
|
echo ""
|
|
|
|
echo ":: Press Enter to continue"
|
|
|
|
read
|
2024-06-16 19:40:41 +02:00
|
|
|
echo ""
|
|
|
|
echo ":: Installing Arduino IDE packages with apt, please enter sudo password:"
|
|
|
|
sudo apt update
|
2024-07-30 19:40:36 +02:00
|
|
|
sudo apt install arduino python3 wget curl xxd
|
2024-06-15 23:59:00 +02:00
|
|
|
echo ":: Ensure directory ${ACLI_DIR} is present"
|
|
|
|
test -d ${ACLI_DIR} || mkdir -p ${ACLI_DIR}
|
|
|
|
echo ":: Please ensure ${ACLI_DIR} is in your \$PATH, I wont do it."
|
|
|
|
echo ""
|
|
|
|
echo ":: Downloading arduino-cli 1.0.0 into ${ACLI_DIR}/"
|
|
|
|
wget -O - "https://github.com/arduino/arduino-cli/releases/download/v1.0.0/arduino-cli_1.0.0_Linux_64bit.tar.gz" | tar -C ${ACLI_DIR} -zxvf - arduino-cli
|
|
|
|
chmod +x ${ACLI}
|
|
|
|
echo ""
|
|
|
|
echo ":: Installing ESP8266 core for Arduino"
|
|
|
|
${ACLI_CMD} core install esp8266:esp8266
|
|
|
|
echo ":: Installing Arduino libraries"
|
|
|
|
for lib in ${!LIBS[@]}
|
|
|
|
do
|
|
|
|
echo " - ${LIBS[$lib]}"
|
|
|
|
done
|
|
|
|
|
|
|
|
for lib in ${!LIBS[@]}
|
|
|
|
do
|
|
|
|
${ACLI_CMD} lib install "${LIBS[$lib]}"
|
|
|
|
done
|
|
|
|
echo ""
|
|
|
|
echo ":: Setup build environment done! You can now build the firmware"
|
|
|
|
echo " with: $0 build"
|
|
|
|
|
|
|
|
;;
|
2024-06-15 01:02:44 +02:00
|
|
|
b|build)
|
2024-06-15 23:59:00 +02:00
|
|
|
check_acli
|
2024-06-16 00:04:28 +02:00
|
|
|
echo ":: Building firmware $VER $BUILD, target dir: $(pwd)/build/"
|
2024-06-15 01:02:44 +02:00
|
|
|
test -d build || mkdir build
|
2024-06-15 02:26:17 +02:00
|
|
|
echo "/* CanGrow_Version.h gets generated from cangrow.sh */
|
|
|
|
|
|
|
|
const char* CanGrowVer = \"${VER}\";
|
2024-06-15 15:24:42 +02:00
|
|
|
const char* CanGrowBuild = \"${BUILD}\";
|
2024-06-15 02:26:17 +02:00
|
|
|
" > Arduino/CanGrow/CanGrow_Version.h
|
2024-12-09 00:07:43 +01:00
|
|
|
${ACLI_CMD} --no-color compile -b ${BOARD} "Arduino/CanGrow/CanGrow.ino" --build-property "build.extra_flags=-DCANGROW_VER=\"${VER}\" -DCANGROW_BUILD=\"${BUILD}\"" --output-dir build/ || exit 1
|
2024-06-15 15:24:42 +02:00
|
|
|
cp build/CanGrow.ino.bin build/CanGrow_v${VER}_${BUILD}.bin
|
2024-06-15 01:02:44 +02:00
|
|
|
;;
|
|
|
|
u|upload)
|
2024-06-15 23:59:00 +02:00
|
|
|
check_acli
|
2024-06-16 00:04:28 +02:00
|
|
|
echo ":: Uploading to $TTY"
|
2024-09-14 15:57:14 +02:00
|
|
|
${ACLI_CMD} --no-color compile -v -b ${BOARD} -u -p $TTY "Arduino/CanGrow/CanGrow.ino"
|
2024-06-15 01:02:44 +02:00
|
|
|
;;
|
2024-06-15 01:17:44 +02:00
|
|
|
w|webupload)
|
2024-06-16 00:04:28 +02:00
|
|
|
echo ":: Uploading to $IP"
|
2024-06-16 00:08:03 +02:00
|
|
|
curl -v http://$IP/system/applyUpdate -X POST -H 'Content-Type: multipart/form-data' -F "firmware=@$(pwd)/build/CanGrow.ino.bin"
|
2024-06-15 01:17:44 +02:00
|
|
|
echo
|
|
|
|
;;
|
2024-06-15 01:02:44 +02:00
|
|
|
m|mon|monitor)
|
2024-06-15 23:59:00 +02:00
|
|
|
check_acli
|
2024-06-16 00:04:28 +02:00
|
|
|
echo ":: Open serial monitor $TTY"
|
2024-09-14 15:57:14 +02:00
|
|
|
${ACLI_CMD} monitor -c baudrate=115200 -b ${BOARD} -p $TTY
|
2024-06-15 01:02:44 +02:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
help
|
|
|
|
;;
|
|
|
|
esac
|