Skip to content

Instantly share code, notes, and snippets.

@Cdaprod
Created March 6, 2024 21:55
Show Gist options
  • Save Cdaprod/c8ab8bcfc4782bf6d1e5cf8d493526c6 to your computer and use it in GitHub Desktop.
Save Cdaprod/c8ab8bcfc4782bf6d1e5cf8d493526c6 to your computer and use it in GitHub Desktop.
Bash script that automates setting up a Python environment, optionally downloads WLED, and flashes firmware to multiple ESP32 devices.
#!/bin/bash
# WLEDFlasher - Effortless WLED Firmware Flashing Tool
cat << EOF
____ ____ _ ____ ____ ___ ____
/ ___| _ \ / \ | _ \| _ \ / _ \| _ \
| | | | | |/ _ \ | |_) | |_) | | | | | | |
| |___| |_| / ___ \| __/| _ <| |_| | |_| |
\____|____/_/ \_\_| |_| \_\\___/|____/
__ ___ _____ ____
\ \ / / | | ____| _ \
\ \ /\ / /| | | _| | | | |
\ V V / | |___| |___| |_| |
\_/\_/ |_____|_____|____/
_____ _ _ ____ _ _ _____ ____
| ___| | / \ / ___|| | | | ____| _ \
| |_ | | / _ \ \___ \| |_| | _| | |_) |
| _| | |___ / ___ \ ___) | _ | |___| _ <
|_| |_____/_/ \_\____/|_| |_|_____|_| \_\
EOF
read -p "Do you need to create a .myenv virtual environment? (y/N) " create_env
if [[ "$create_env" == "y" ]]; then
echo "Setting up environment..."
python3 -m venv .myenv
source .myenv/bin/activate
pip3 install platformio
fi
read -p "Do you want to download WLED to a temporary directory? (y/N) " download_wled
if [[ "$download_wled" == "y" ]]; then
read -p "Enter the full path to your WLED directory: " WLED_DIR
# Add the command to download WLED to the specified directory here
# This is a placeholder, adjust it based on how you plan to download WLED
# git clone https://github.com/Aircoookie/WLED.git "$WLED_DIR"
fi
# Verify directory and change to it
if [[ -d "$WLED_DIR" ]]; then
cd "$WLED_DIR"
else
echo "Directory does not exist. Exiting."
exit 1
fi
# Ask for the number of devices
read -p "How many devices do you want to flash? " num_devices
# Loop for the number of devices you want to flash
for ((i=1; i<=num_devices; i++)); do
echo "Flashing device $i..."
# Compile the firmware
pio run
# Upload the firmware to ESP32-S2
pio run -t upload
if [[ $i -lt $num_devices ]]; then
echo "Please disconnect the current device and connect the next one, then press any key to continue..."
read -n 1 -s -r
fi
done
echo "Flashing process completed for all devices."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment