Skip to content

Instantly share code, notes, and snippets.

@devilmonastery
Created May 4, 2022 14:12
Show Gist options
  • Save devilmonastery/f636256db79aaba0692eaf6d08c6c5ce to your computer and use it in GitHub Desktop.
Save devilmonastery/f636256db79aaba0692eaf6d08c6c5ce to your computer and use it in GitHub Desktop.
configure bootstrapped shelly h&t
#!/bin/bash
devid=$1
if [[ "${devid}" == "" ]]; then
echo "$0 deviceid"
exit
fi
TARGET="${devid}.local."
LOGFILE="${devid}.log"
LOG () {
when=$(date '+%Y-%m-%d %H:%M:%S')
echo "${when}] $1"
echo "${when}] $1" >> "${LOGFILE}"
}
LOG "Waiting for ping..."
until ip=$(ping -t 1 -c 1 ${TARGET} | head -1 | sed 's/PING .*(\(.*\)).*/\1/g'); do sleep 1; done
LOG "Found on ${ip}"
LOG "Setting name..."
curl -s -o - "http://${TARGET}/settings?name=${devid}" >> "${LOGFILE}"
LOG "Setting temp threshold..."
curl -s -o - "http://${TARGET}/settings?temperature_threshold=0.5" >> "${LOGFILE}"
echo >> "${LOGFILE}"
LOG "Setting report URL..."
curl -s -o - "http://${TARGET}/settings/actions?index=0&name=report_url&enabled=true&urls[]=http://140.238.208.121:9876/report" >> "${LOGFILE}"
echo >> "${LOGFILE}"
LOG "Getting settings..."
curl -s -o - "http://${TARGET}/settings" >> "${LOGFILE}"
echo >> "${LOGFILE}"
LOG "now, check the settings via the UI"
open http://${TARGET}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment