From 378b94612610257b70e0c8a55a68c9f971846e01 Mon Sep 17 00:00:00 2001 From: Scott Hibbard <40345296+SCHibbard@users.noreply.github.com> Date: Sat, 14 Sep 2024 15:20:27 -0500 Subject: [PATCH 1/7] Add files via upload Script to create persistent IP routing for Powerwall TDAPI interface. --- add_route.sh | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 add_route.sh diff --git a/add_route.sh b/add_route.sh new file mode 100644 index 00000000..e3ce2902 --- /dev/null +++ b/add_route.sh @@ -0,0 +1,87 @@ +#!/bin/bash +# +# add_route.sh +# Script to setup persistant TEDAPI Routing for Powerwall Dashboard +# Version: 1.0.0 +# By Scott Hibbard - 2024-09-14 +# + +CRONTAB="/var/spool/cron/crontabs/root" +PW_IP="" +SCRIPT_NAME="TDAPI_routing" +DIR="/root/scripts" + +echo "Setup script for persistant Powerall Dashboard TEDAPI Interface network routing" +echo "-------------------------------------------------------------------------------" +echo +echo "This script will require root privileges to read & set a startup cron task." +read -r -p "Do you want to run this script? [Y/n] " response +if [[ "$response" =~ ^([nN][oO]|[nN])$ ]]; then + echo "Cancel" + exit 1 +fi + +OS=$(uname -s) + +if $(ip route | grep -qw "192.168.91.0/24"); then + read -r -p "192.168.91.0/24 routing is already in routing table. Still want to run this? [y/N] " response + if [[ ! "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then + echo "Cancel" + exit 1 + fi +fi + +# Running Linux? +if [[ "${OS}" == "Linux" ]]; then + if ! sudo test -d ${DIR}; then + sudo mkdir ${DIR} + echo "Created folder ${DIR}." + fi + + if [ -f ${DIR}/${SCRIPT_NAME}.sh ]; then + echo "Boot script already exists." + else + while [ "$PW_IP" == "" ]; do + read -p 'Enter Powerwall IP Address: ' PW_IP + done + echo "" + cat > ${SCRIPT_NAME}.tmp << EOF +#!/bin/bash +declare -i i=0 +while (( i < 15 )); do + RETURN="\$(ip route add 192.168.91.0/24 via ${PW_IP} 2>&1)" + if [ "\$RETURN" != "RTNETLINK answers: File exists" ]; then + declare -i i=i+1 + sleep 1 + else + RETURN="Success" + break + fi +done + +# Uncomment the lines below to log results of executing this script +# NOW="\$(date)" +# echo "\${NOW}: result=\${RETURN}, delay=\${i}" >> ${DIR}/${SCRIPT_NAME}.log + +EOF + chmod 775 ${SCRIPT_NAME}.tmp + sudo chown 0 ${SCRIPT_NAME}.tmp + sudo mv ${SCRIPT_NAME}.tmp ${DIR}/${SCRIPT_NAME}.sh + fi + + if ! $(sudo cat ${CRONTAB} | grep -qw ${DIR}/${SCRIPT_NAME}.sh); then + sudo crontab -u root -l > ${SCRIPT_NAME}".cron" + echo "@reboot ${DIR}/${SCRIPT_NAME}.sh" >> ${SCRIPT_NAME}".cron" + sudo crontab -u root ${SCRIPT_NAME}".cron" + rm ${SCRIPT_NAME}".cron" + echo "Cron entry added." + else + echo "Cron line already exists." + echo "Installation complete." + fi + +else + echo "You are running '$OS', which is not supported in this script." + echo "Maybe you could add code to support '$OS'!" + exit 1 +fi From b7fb7bf692fbec5ec70bcaa3a2e1f642023ddae5 Mon Sep 17 00:00:00 2001 From: Scott Hibbard <40345296+SCHibbard@users.noreply.github.com> Date: Sat, 14 Sep 2024 15:23:50 -0500 Subject: [PATCH 2/7] Delete add_route.sh --- add_route.sh | 87 ---------------------------------------------------- 1 file changed, 87 deletions(-) delete mode 100644 add_route.sh diff --git a/add_route.sh b/add_route.sh deleted file mode 100644 index e3ce2902..00000000 --- a/add_route.sh +++ /dev/null @@ -1,87 +0,0 @@ -#!/bin/bash -# -# add_route.sh -# Script to setup persistant TEDAPI Routing for Powerwall Dashboard -# Version: 1.0.0 -# By Scott Hibbard - 2024-09-14 -# - -CRONTAB="/var/spool/cron/crontabs/root" -PW_IP="" -SCRIPT_NAME="TDAPI_routing" -DIR="/root/scripts" - -echo "Setup script for persistant Powerall Dashboard TEDAPI Interface network routing" -echo "-------------------------------------------------------------------------------" -echo -echo "This script will require root privileges to read & set a startup cron task." -read -r -p "Do you want to run this script? [Y/n] " response -if [[ "$response" =~ ^([nN][oO]|[nN])$ ]]; then - echo "Cancel" - exit 1 -fi - -OS=$(uname -s) - -if $(ip route | grep -qw "192.168.91.0/24"); then - read -r -p "192.168.91.0/24 routing is already in routing table. Still want to run this? [y/N] " response - if [[ ! "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then - echo "Cancel" - exit 1 - fi -fi - -# Running Linux? -if [[ "${OS}" == "Linux" ]]; then - if ! sudo test -d ${DIR}; then - sudo mkdir ${DIR} - echo "Created folder ${DIR}." - fi - - if [ -f ${DIR}/${SCRIPT_NAME}.sh ]; then - echo "Boot script already exists." - else - while [ "$PW_IP" == "" ]; do - read -p 'Enter Powerwall IP Address: ' PW_IP - done - echo "" - cat > ${SCRIPT_NAME}.tmp << EOF -#!/bin/bash -declare -i i=0 -while (( i < 15 )); do - RETURN="\$(ip route add 192.168.91.0/24 via ${PW_IP} 2>&1)" - if [ "\$RETURN" != "RTNETLINK answers: File exists" ]; then - declare -i i=i+1 - sleep 1 - else - RETURN="Success" - break - fi -done - -# Uncomment the lines below to log results of executing this script -# NOW="\$(date)" -# echo "\${NOW}: result=\${RETURN}, delay=\${i}" >> ${DIR}/${SCRIPT_NAME}.log - -EOF - chmod 775 ${SCRIPT_NAME}.tmp - sudo chown 0 ${SCRIPT_NAME}.tmp - sudo mv ${SCRIPT_NAME}.tmp ${DIR}/${SCRIPT_NAME}.sh - fi - - if ! $(sudo cat ${CRONTAB} | grep -qw ${DIR}/${SCRIPT_NAME}.sh); then - sudo crontab -u root -l > ${SCRIPT_NAME}".cron" - echo "@reboot ${DIR}/${SCRIPT_NAME}.sh" >> ${SCRIPT_NAME}".cron" - sudo crontab -u root ${SCRIPT_NAME}".cron" - rm ${SCRIPT_NAME}".cron" - echo "Cron entry added." - else - echo "Cron line already exists." - echo "Installation complete." - fi - -else - echo "You are running '$OS', which is not supported in this script." - echo "Maybe you could add code to support '$OS'!" - exit 1 -fi From cce17578b5de0057802cbc1888bef2007ea337b8 Mon Sep 17 00:00:00 2001 From: Scott Hibbard <40345296+SCHibbard@users.noreply.github.com> Date: Sat, 14 Sep 2024 15:30:26 -0500 Subject: [PATCH 3/7] New IP routing script Script to create persistent IP routing for Powerwall TDAPI interface. --- add_route.sh | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 add_route.sh diff --git a/add_route.sh b/add_route.sh new file mode 100644 index 00000000..e3ce2902 --- /dev/null +++ b/add_route.sh @@ -0,0 +1,87 @@ +#!/bin/bash +# +# add_route.sh +# Script to setup persistant TEDAPI Routing for Powerwall Dashboard +# Version: 1.0.0 +# By Scott Hibbard - 2024-09-14 +# + +CRONTAB="/var/spool/cron/crontabs/root" +PW_IP="" +SCRIPT_NAME="TDAPI_routing" +DIR="/root/scripts" + +echo "Setup script for persistant Powerall Dashboard TEDAPI Interface network routing" +echo "-------------------------------------------------------------------------------" +echo +echo "This script will require root privileges to read & set a startup cron task." +read -r -p "Do you want to run this script? [Y/n] " response +if [[ "$response" =~ ^([nN][oO]|[nN])$ ]]; then + echo "Cancel" + exit 1 +fi + +OS=$(uname -s) + +if $(ip route | grep -qw "192.168.91.0/24"); then + read -r -p "192.168.91.0/24 routing is already in routing table. Still want to run this? [y/N] " response + if [[ ! "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then + echo "Cancel" + exit 1 + fi +fi + +# Running Linux? +if [[ "${OS}" == "Linux" ]]; then + if ! sudo test -d ${DIR}; then + sudo mkdir ${DIR} + echo "Created folder ${DIR}." + fi + + if [ -f ${DIR}/${SCRIPT_NAME}.sh ]; then + echo "Boot script already exists." + else + while [ "$PW_IP" == "" ]; do + read -p 'Enter Powerwall IP Address: ' PW_IP + done + echo "" + cat > ${SCRIPT_NAME}.tmp << EOF +#!/bin/bash +declare -i i=0 +while (( i < 15 )); do + RETURN="\$(ip route add 192.168.91.0/24 via ${PW_IP} 2>&1)" + if [ "\$RETURN" != "RTNETLINK answers: File exists" ]; then + declare -i i=i+1 + sleep 1 + else + RETURN="Success" + break + fi +done + +# Uncomment the lines below to log results of executing this script +# NOW="\$(date)" +# echo "\${NOW}: result=\${RETURN}, delay=\${i}" >> ${DIR}/${SCRIPT_NAME}.log + +EOF + chmod 775 ${SCRIPT_NAME}.tmp + sudo chown 0 ${SCRIPT_NAME}.tmp + sudo mv ${SCRIPT_NAME}.tmp ${DIR}/${SCRIPT_NAME}.sh + fi + + if ! $(sudo cat ${CRONTAB} | grep -qw ${DIR}/${SCRIPT_NAME}.sh); then + sudo crontab -u root -l > ${SCRIPT_NAME}".cron" + echo "@reboot ${DIR}/${SCRIPT_NAME}.sh" >> ${SCRIPT_NAME}".cron" + sudo crontab -u root ${SCRIPT_NAME}".cron" + rm ${SCRIPT_NAME}".cron" + echo "Cron entry added." + else + echo "Cron line already exists." + echo "Installation complete." + fi + +else + echo "You are running '$OS', which is not supported in this script." + echo "Maybe you could add code to support '$OS'!" + exit 1 +fi From 8d7dbdc4975bf1c4e01adc3229d7a6e6167817fc Mon Sep 17 00:00:00 2001 From: Scott Hibbard <40345296+SCHibbard@users.noreply.github.com> Date: Sun, 15 Sep 2024 14:03:57 -0500 Subject: [PATCH 4/7] Update add_route.sh Added support for other operating systems, general code improvements. --- add_route.sh | 110 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 69 insertions(+), 41 deletions(-) diff --git a/add_route.sh b/add_route.sh index e3ce2902..b802c91a 100644 --- a/add_route.sh +++ b/add_route.sh @@ -2,14 +2,18 @@ # # add_route.sh # Script to setup persistant TEDAPI Routing for Powerwall Dashboard -# Version: 1.0.0 -# By Scott Hibbard - 2024-09-14 +# Version: 1.0.1 +# By Scott Hibbard - 2024-09-15 # CRONTAB="/var/spool/cron/crontabs/root" PW_IP="" -SCRIPT_NAME="TDAPI_routing" +SCRIPT_NAME="TEDAPI_routing" DIR="/root/scripts" +LINUX_IP="192.168.91.0/24" +TARGET_IP="192.168.91.1" +NETMASK="255.255.255.255" +OS=$(uname -s) echo "Setup script for persistant Powerall Dashboard TEDAPI Interface network routing" echo "-------------------------------------------------------------------------------" @@ -21,35 +25,40 @@ if [[ "$response" =~ ^([nN][oO]|[nN])$ ]]; then exit 1 fi -OS=$(uname -s) - -if $(ip route | grep -qw "192.168.91.0/24"); then - read -r -p "192.168.91.0/24 routing is already in routing table. Still want to run this? [y/N] " response - if [[ ! "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then - echo "Cancel" - exit 1 - fi -fi +while [ "$PW_IP" == "" ]; do + read -p 'Enter Powerwall IP Address: ' PW_IP +done -# Running Linux? +# Detect OS and run commands accordingly if [[ "${OS}" == "Linux" ]]; then - if ! sudo test -d ${DIR}; then - sudo mkdir ${DIR} - echo "Created folder ${DIR}." - fi - - if [ -f ${DIR}/${SCRIPT_NAME}.sh ]; then - echo "Boot script already exists." - else - while [ "$PW_IP" == "" ]; do - read -p 'Enter Powerwall IP Address: ' PW_IP - done - echo "" - cat > ${SCRIPT_NAME}.tmp << EOF + # Check if running under WSL + if grep -qi "microsoft" /proc/version; then + echo "WSL detected - unable to add route automatically." + echo "To add the route, open an Administrator Shell in Windows and run:" + echo " route -p add ${TARGET_IP} mask ${NETMASK} ${PW_IP}" + echo "" + exit 1 + else + echo "Native Linux detected" + if $(ip route | grep -qw ${LINUX_IP}); then + read -r -p "${LINUX_IP} routing already in routing table. Still want to run this? [y/N] " response + if [[ ! "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then + echo "Cancel" + exit 1 + fi + fi + + sudo mkdir -p ${DIR} + + if [ -f ${DIR}/${SCRIPT_NAME}.sh ]; then + echo "Boot script already exists." + else + echo "" + cat > ${SCRIPT_NAME}.tmp << EOF #!/bin/bash declare -i i=0 while (( i < 15 )); do - RETURN="\$(ip route add 192.168.91.0/24 via ${PW_IP} 2>&1)" + RETURN="\$(ip route add ${LINUX_IP} via ${PW_IP} 2>&1)" if [ "\$RETURN" != "RTNETLINK answers: File exists" ]; then declare -i i=i+1 sleep 1 @@ -64,22 +73,41 @@ done # echo "\${NOW}: result=\${RETURN}, delay=\${i}" >> ${DIR}/${SCRIPT_NAME}.log EOF - chmod 775 ${SCRIPT_NAME}.tmp - sudo chown 0 ${SCRIPT_NAME}.tmp - sudo mv ${SCRIPT_NAME}.tmp ${DIR}/${SCRIPT_NAME}.sh - fi + chmod 775 ${SCRIPT_NAME}.tmp + sudo chown 0 ${SCRIPT_NAME}.tmp + sudo mv ${SCRIPT_NAME}.tmp ${DIR}/${SCRIPT_NAME}.sh + fi - if ! $(sudo cat ${CRONTAB} | grep -qw ${DIR}/${SCRIPT_NAME}.sh); then - sudo crontab -u root -l > ${SCRIPT_NAME}".cron" - echo "@reboot ${DIR}/${SCRIPT_NAME}.sh" >> ${SCRIPT_NAME}".cron" - sudo crontab -u root ${SCRIPT_NAME}".cron" - rm ${SCRIPT_NAME}".cron" - echo "Cron entry added." - else - echo "Cron line already exists." - echo "Installation complete." + if ! (sudo test -f ${CRONTAB}) || ! (sudo grep -qw "${DIR}/${SCRIPT_NAME}.sh" ${CRONTAB}); then + (sudo crontab -u root -l 2>/dev/null; echo "@reboot ${DIR}/${SCRIPT_NAME}.sh") | sudo crontab -u root - + echo "Cron entry added." + else + echo "Cron line already exists." + fi + sudo /bin/bash ${DIR}/${SCRIPT_NAME}.sh + echo "Installation complete." + exit 0 fi - +elif [[ "${OS}" == "Darwin" ]]; then + echo "macOS detected - adding permanent route for Wi-Fi" # TODO: Support for other network interfaces (Ethernet, etc.) + if sudo networksetup -setadditionalroutes Wi-Fi "${TARGET_IP}" "${NETMASK}" "${PW_IP}"; then + echo "Route added successfully." + else + echo "Failed to add the route. Please check your network configuration or permissions." + exit 1 + fi + echo "" + exit 0 +elif [[ "${OS}" =~ MINGW* || "${OS}" =~ CYGWIN* ]]; then + echo "Windows shell detected - attempting to add route automatically." + if route -p add "${TARGET_IP}" mask "${NETMASK}" "${PW_IP}"; then + echo "Route added successfully." + else + echo "Failed to add the route. Please ensure you are running as Administrator." + exit 1 + fi + echo "" + exit 0 else echo "You are running '$OS', which is not supported in this script." echo "Maybe you could add code to support '$OS'!" From b86485622549575716ae6fd3b19bc4cdd390f386 Mon Sep 17 00:00:00 2001 From: Jason Cox Date: Sun, 15 Sep 2024 16:56:28 -0700 Subject: [PATCH 5/7] Add boot script comments --- add_route.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/add_route.sh b/add_route.sh index b802c91a..670bb612 100644 --- a/add_route.sh +++ b/add_route.sh @@ -51,11 +51,15 @@ if [[ "${OS}" == "Linux" ]]; then sudo mkdir -p ${DIR} if [ -f ${DIR}/${SCRIPT_NAME}.sh ]; then - echo "Boot script already exists." + echo "Boot script already exists (${DIR}/${SCRIPT_NAME}.sh)." else echo "" cat > ${SCRIPT_NAME}.tmp << EOF #!/bin/bash +# +# Add network route to Powerwall TEDAPI address on boot. +# This script is auto-generated by Powerwall Dashboard add_route.sh +# declare -i i=0 while (( i < 15 )); do RETURN="\$(ip route add ${LINUX_IP} via ${PW_IP} 2>&1)" @@ -73,9 +77,9 @@ done # echo "\${NOW}: result=\${RETURN}, delay=\${i}" >> ${DIR}/${SCRIPT_NAME}.log EOF - chmod 775 ${SCRIPT_NAME}.tmp - sudo chown 0 ${SCRIPT_NAME}.tmp - sudo mv ${SCRIPT_NAME}.tmp ${DIR}/${SCRIPT_NAME}.sh + chmod 775 ${SCRIPT_NAME}.tmp + sudo chown 0 ${SCRIPT_NAME}.tmp + sudo mv ${SCRIPT_NAME}.tmp ${DIR}/${SCRIPT_NAME}.sh fi if ! (sudo test -f ${CRONTAB}) || ! (sudo grep -qw "${DIR}/${SCRIPT_NAME}.sh" ${CRONTAB}); then From abdbca77c74ffb9e504e63f479da5822a8337a3e Mon Sep 17 00:00:00 2001 From: Jason Cox Date: Sun, 15 Sep 2024 20:18:28 -0700 Subject: [PATCH 6/7] Add prompts to exit in add_route.sh for better WinOS user experience --- add_route.sh | 2 ++ 1 file changed, 2 insertions(+) mode change 100644 => 100755 add_route.sh diff --git a/add_route.sh b/add_route.sh old mode 100644 new mode 100755 index 670bb612..5898539d --- a/add_route.sh +++ b/add_route.sh @@ -37,6 +37,7 @@ if [[ "${OS}" == "Linux" ]]; then echo "To add the route, open an Administrator Shell in Windows and run:" echo " route -p add ${TARGET_IP} mask ${NETMASK} ${PW_IP}" echo "" + read -p "Press Enter to exit..." exit 1 else echo "Native Linux detected" @@ -108,6 +109,7 @@ elif [[ "${OS}" =~ MINGW* || "${OS}" =~ CYGWIN* ]]; then echo "Route added successfully." else echo "Failed to add the route. Please ensure you are running as Administrator." + read -p "Press Enter to exit..." exit 1 fi echo "" From 0746846fad2c89ce3ae66d32e9dde9838b430e71 Mon Sep 17 00:00:00 2001 From: Jason Cox Date: Sun, 15 Sep 2024 20:26:59 -0700 Subject: [PATCH 7/7] Bump version to 4.5.3 and update release notes for TEDAPI route tool --- RELEASE.md | 5 +++++ VERSION | 2 +- upgrade.sh | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index ba9f19b4..593c008d 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,5 +1,10 @@ # RELEASE NOTES +## v4.5.3 - TEDAPI Route Tool + +* New `add_route.sh` tool to add persistent TEDAPI network routing by @SCHibbard in https://github.com/jasonacox/Powerwall-Dashboard/pull/520 +* User can run `add_route.sh` to create a persistent route to the Powerwall TEDAPI endpoint. This can be run before `setup.sh` to allow [extended data local mode](https://github.com/jasonacox/Powerwall-Dashboard?tab=readme-ov-file#local-mode) for PW3 and PW2/+ systems. Existing user can also run this to set the route and re-run `setup.sh` to select the extended local mode. + ## v4.5.2 - PW3 and FleetAPI Fixes * Updates [pyPowerwall to v0.11.1](https://github.com/jasonacox/pypowerwall/pull/112) to fix a PW3 bug in TEDAPI and a site ID bug in FleetAPI. diff --git a/VERSION b/VERSION index 6cedcff6..4e298cc9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.5.2 +4.5.3 diff --git a/upgrade.sh b/upgrade.sh index 60f72280..f611ebbc 100755 --- a/upgrade.sh +++ b/upgrade.sh @@ -6,7 +6,7 @@ set -e # Set Globals -VERSION="4.5.2" +VERSION="4.5.3" CURRENT="Unknown" COMPOSE_ENV_FILE="compose.env" INFLUXDB_ENV_FILE="influxdb.env"