2019-04-18 16:32:35 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-02-13 14:25:57 +01:00
|
|
|
MQTTSERVER=$1
|
|
|
|
MQTTPREFIX=$2
|
2021-03-21 18:21:04 +01:00
|
|
|
CUSTOMFILE=$3
|
2019-04-18 16:32:35 +02:00
|
|
|
|
|
|
|
FLASHTOOL=./tools/tcpFlash.py
|
2021-03-21 20:38:03 +01:00
|
|
|
TOOLDIR=tools/
|
|
|
|
DIET=bin/luasrcdiet
|
2019-04-18 16:32:35 +02:00
|
|
|
|
2021-02-13 14:25:57 +01:00
|
|
|
UPGRADEPREP=/tmp/upgradeCMD4clock.txt
|
|
|
|
|
2019-04-18 16:32:35 +02:00
|
|
|
if [ ! -f $FLASHTOOL ]; then
|
|
|
|
echo "Execute the script in root folder of the project"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2021-02-13 14:25:57 +01:00
|
|
|
if [[ "$MQTTPREFIX" == "" ]] || [[ "$MQTTSERVER" == "" ]]; then
|
|
|
|
echo "MQTTSERVER: ip address to mqtt server"
|
|
|
|
echo "MQTTPREFIX: configured prefex in MQTT of ESP required"
|
2019-04-18 16:32:35 +02:00
|
|
|
echo "usage:"
|
2021-02-13 14:25:57 +01:00
|
|
|
echo "$0 <MQTTSERVER> <MQTTPREFIX>"
|
|
|
|
echo "$0 192.168.0.2 basetopic"
|
2019-04-18 16:32:35 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-03-21 20:38:03 +01:00
|
|
|
# Prepare all files on host
|
|
|
|
if [[ "$CUSTOMFILE" == "" ]]; then
|
|
|
|
FILES="displayword.lua main.lua timecore.lua webpage.html webserver.lua wordclock.lua init.lua"
|
|
|
|
echo "Start Flasing ..."
|
|
|
|
else
|
|
|
|
FILES=$CUSTOMFILE
|
|
|
|
echo "Start Flasing $FILES ..."
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Convert files, if necessary
|
|
|
|
if [ "$FILES" != "config.lua" ]; then
|
|
|
|
echo "Generate DIET version of the files"
|
|
|
|
OUTFILES=""
|
|
|
|
ROOTDIR=$PWD
|
|
|
|
cd $TOOLDIR
|
|
|
|
for f in $FILES; do
|
|
|
|
if [[ "$f" == *.lua ]] && [[ "$f" != init.lua ]]; then
|
|
|
|
echo "Compress $f ..."
|
|
|
|
out=$(echo "$f" | sed 's/.lua/_diet.lua/g')
|
|
|
|
$DIET ../$f -o ../diet/$out >> /dev/null
|
|
|
|
OUTFILES="$OUTFILES diet/$out"
|
|
|
|
else
|
|
|
|
OUTFILES="$OUTFILES $f"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
FILES=$OUTFILES
|
|
|
|
cd $ROOTDIR
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2019-04-18 16:32:35 +02:00
|
|
|
# check the connection
|
2021-02-13 14:25:57 +01:00
|
|
|
echo "Searching $MQTTPREFIX ..."
|
|
|
|
mosquitto_sub -h $MQTTSERVER -t "$MQTTPREFIX/#" -C 1 -v
|
2019-04-18 16:32:35 +02:00
|
|
|
if [ $? -ne 0 ]; then
|
2021-02-13 14:25:57 +01:00
|
|
|
echo "Entered Wordclock address: $MQTTPREFIX on $MQTTSERVER is NOT online"
|
2019-04-18 16:32:35 +02:00
|
|
|
exit 2
|
|
|
|
fi
|
2022-01-06 16:35:41 +01:00
|
|
|
echo "Activate Telnet server ..."
|
|
|
|
TELNETIP="empty"
|
|
|
|
while [ "$TELNETIP" = "empty" ]; do
|
|
|
|
date
|
|
|
|
mosquitto_pub -h $MQTTSERVER -t "$MQTTPREFIX/cmd/telnet" -m "a"
|
|
|
|
TELNETIP=$(mosquitto_sub -h $MQTTSERVER -t "$MQTTPREFIX/telnet" -C 1 -W 30)
|
|
|
|
done
|
|
|
|
|
2021-03-21 18:21:04 +01:00
|
|
|
echo "Upgrading $MQTTPREFIX via telenet on $TELNETIP ..."
|
|
|
|
sleep 1
|
|
|
|
echo "if (mlt ~= nil) then mlt:unregister() end" > $UPGRADEPREP
|
2021-02-13 14:25:57 +01:00
|
|
|
echo "uart.write(0, tostring(node.heap())" >> $UPGRADEPREP
|
2021-03-21 18:21:04 +01:00
|
|
|
echo "collectgarbage()" >> $UPGRADEPREP
|
|
|
|
echo "" >> $UPGRADEPREP
|
|
|
|
echo "download = string.char(0,0,64)" >> $UPGRADEPREP
|
2021-02-13 14:25:57 +01:00
|
|
|
echo "w = string.char(0,0,0)" >> $UPGRADEPREP
|
2021-03-21 18:21:04 +01:00
|
|
|
echo "ws2812.write(w:rep(4) .. download .. w:rep(15) .. download .. w:rep(9) .. download .. w:rep(30) .. download .. w:rep(41) .. download )" >> $UPGRADEPREP
|
|
|
|
echo "collectgarbage()" >> $UPGRADEPREP
|
2021-02-13 14:25:57 +01:00
|
|
|
$FLASHTOOL -f $UPGRADEPREP -t $TELNETIP -v
|
2019-04-18 19:31:48 +02:00
|
|
|
|
2019-04-18 16:32:35 +02:00
|
|
|
for f in $FILES; do
|
|
|
|
if [ ! -f $f ]; then
|
|
|
|
echo "Cannot find $f"
|
|
|
|
echo "place the terminal into the folder where the lua files are present"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-03-21 20:38:03 +01:00
|
|
|
espFile=$(echo "$f" | sed 's;diet/;;g')
|
|
|
|
echo "------------- $espFile ------------"
|
|
|
|
$FLASHTOOL -t $TELNETIP -f $f -o $espFile
|
2019-04-18 16:32:35 +02:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "STOOOOP"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2019-04-18 16:41:04 +02:00
|
|
|
echo "TODO: Reboot the ESP"
|
2021-02-13 14:25:57 +01:00
|
|
|
#echo "node.restart()" | nc $TELNETIP 23
|
2019-04-18 16:32:35 +02:00
|
|
|
|
|
|
|
exit 0
|