Created
April 6, 2020 17:32
-
-
Save KevinOConnor/7912ff3cdab6c1644ee0a2b17734c567 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Flash a binary to a device uploading over mqtt | |
ESPDIR="${HOME}/esphome" | |
ESPBIN="${ESPDIR}/esphome-env/bin/esphome" | |
# Parse args | |
if [ $# != 2 ]; then | |
echo "Usage: $0 <esphome_config> <mqtt_prefix>" | |
exit 1 | |
fi | |
ESPHOME_CONFIG="$1" | |
MQTT_PREFIX="$2" | |
# Compile software | |
echo "" | |
echo "" | |
echo "=================== Compiling software" | |
cd "${ESPDIR}" | |
${ESPBIN} "$ESPHOME_CONFIG" compile | |
# Turn on "ota" update mode and wait for connection | |
echo "" | |
echo "" | |
echo "=================== Waiting for device to connect" | |
mosquitto_pub -t "${MQTT_PREFIX}/ota_mode" -r -m "ON" | |
mosquitto_sub -t "${MQTT_PREFIX}/debug" -R -C 1 > /dev/null | |
# Turn off "ota" update mode and upload new binary | |
echo "" | |
echo "" | |
echo "=================== Uploading" | |
sleep 2 | |
mosquitto_pub -t "${MQTT_PREFIX}/ota_mode" -r -n | |
${ESPBIN} "$ESPHOME_CONFIG" upload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment