Skip to content

Instantly share code, notes, and snippets.

@MaxPeal
Forked from ixs/tasmota-configure.sh
Created January 31, 2022 16:44
Show Gist options
  • Save MaxPeal/16bd48f8e64a99c446bc1414578fe4ed to your computer and use it in GitHub Desktop.
Save MaxPeal/16bd48f8e64a99c446bc1414578fe4ed to your computer and use it in GitHub Desktop.
Tasmota mass configuration
#!/bin/bash
#
# Do initial configuration of a SP111 plug on your local wifi
#
# Licensed under the GPLv3+
#
TEMPLATE='{"NAME":"SP111 v1.1","GPIO":[56,0,158,0,132,134,0,0,131,17,0,21,0],"FLAG":0,"BASE":45}'
function uriencode {
jq -nr --arg v "$1" '$v|@uri'
}
echo -n "Finding Espressif devices on local network... "
IP_ADDRS=$(arp-scan -I eth0 192.168.2.0/24 | awk '/Espressif/ { print $1 }')
echo $(echo "$IP_ADDRS" | wc -l)" devices found"
for IP in $IP_ADDRS; do
echo "***********************"
echo "Working on $IP"
echo "***********************"
if ! ping -q -w 1 -c 1 $IP > /dev/null 2>&1; then
echo "$IP unreachable, skipping..."
continue
fi
echo -n "Getting hostname... "
HOSTNAME=$(curl -s "http://$IP/cm?cmnd="$(uriencode "Status 5") | jq -r '.StatusNET.Hostname')
echo $HOSTNAME
echo -n "Setting Device name to hostname..."
curl -s "http://$IP/cm?cmnd="$(uriencode "DeviceName $HOSTNAME")
echo
echo -n "Setting Friendly name to hostname..."
curl -s "http://$IP/cm?cmnd="$(uriencode "FriendlyName1 $HOSTNAME")
echo
echo -n "Setting Template... "
curl -s "http://$IP/cm?cmnd="$(uriencode "Template $TEMPLATE")
echo
echo -n "Activating Template... "
curl -s "http://$IP/cm?cmnd="$(uriencode "Module 0")
echo
echo "Waiting for $HOSTNAME to reboot"
sleep 10
echo -n "Applying further configuration settings... "
curl -s "http://$IP/cm?cmnd="$(uriencode "Backlog VoltageSet 235; SetOption21 1; SetOption55 1; TelePeriod 10; Timezone 99; PowerOnState 1; Power 1")
echo
echo -n "Upgrading Firmware... "
curl -s "http://$IP/cm?cmnd="$(uriencode "Upgrade 1")
echo
done
#!/bin/bash
#
# Do initial wifi configuration to have a SP111 plug join your local wifi
#
# Licensed under the GPLv3+
#
WIFI_IF=wlan0
WIFI_NETS=$(iw dev $WIFI_IF scan | awk '/SSID: tasmota-/ { print $2 }')
echo "Killing wpa_supplicant"
killall wpa_supplicant
ip link set $WIFI_IF up
echo -n "Scanning for wifi networks... "
echo $(echo -n "$WIFI_NETS" | wc -l) tasmota networks found.
SSID1=your_ssid_1
PWD1=your_pwd_1
SSID2=your_ssid_2
PWD2=your_pwd_2
for SSID in $WIFI_NETS; do
echo "Connecting to $SSID..."
ip addr flush dev $WIFI_IF
iw $WIFI_IF connect $SSID
sleep 5
if iw dev $WIFI_IF link; then
echo connected
else
echo "not connected. skipping"
fi
dhclient -i $WIFI_IF -1
GATEWAY=$(ip -4 route list 0/0 dev $WIFI_IF | awk '{ print $3 }' | head -n 1)
if ! ping -w 1 -c 1 $GATEWAY; then
echo $IP not reachable. Skipping...
continue
fi
curl "http://$GATEWAY/wi?s1=$SSID1&p1=$PWD1&s2=$SSID2&p2=$PWD2&h=%25s-%2504d&c=&save="
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment