Remote update worked
This commit is contained in:
parent
7a2814d327
commit
91ab8609b9
@ -5,6 +5,8 @@ MQTTPREFIX=$2
|
||||
CUSTOMFILE=$3
|
||||
|
||||
FLASHTOOL=./tools/tcpFlash.py
|
||||
TOOLDIR=tools/
|
||||
DIET=bin/luasrcdiet
|
||||
|
||||
UPGRADEPREP=/tmp/upgradeCMD4clock.txt
|
||||
|
||||
@ -22,6 +24,37 @@ if [[ "$MQTTPREFIX" == "" ]] || [[ "$MQTTSERVER" == "" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
# check the connection
|
||||
echo "Searching $MQTTPREFIX ..."
|
||||
mosquitto_sub -h $MQTTSERVER -t "$MQTTPREFIX/#" -C 1 -v
|
||||
@ -44,23 +77,15 @@ echo "ws2812.write(w:rep(4) .. download .. w:rep(15) .. download .. w:rep(9) ..
|
||||
echo "collectgarbage()" >> $UPGRADEPREP
|
||||
$FLASHTOOL -f $UPGRADEPREP -t $TELNETIP -v
|
||||
|
||||
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
|
||||
|
||||
exit 2
|
||||
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
|
||||
echo "------------- $f ------------"
|
||||
$FLASHTOOL -t $TELNETIP -f $f
|
||||
espFile=$(echo "$f" | sed 's;diet/;;g')
|
||||
echo "------------- $espFile ------------"
|
||||
$FLASHTOOL -t $TELNETIP -f $f -o $espFile
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "STOOOOP"
|
||||
exit 1
|
||||
|
@ -43,7 +43,7 @@ def sendCmd(s, message, cleaningEnter=False):
|
||||
print "ERROR, received : " + reply
|
||||
return False
|
||||
|
||||
def main(nodeip, luafile, volatile=None):
|
||||
def main(nodeip, luafile, volatile=None, outfile=None):
|
||||
if ( not os.path.isfile(luafile) ):
|
||||
print "The file " + luafile + " is not available"
|
||||
else:
|
||||
@ -71,12 +71,16 @@ def main(nodeip, luafile, volatile=None):
|
||||
print "NOT communicating with an ESP8266 running LUA (nodemcu) firmware"
|
||||
s.close()
|
||||
sys.exit(3)
|
||||
|
||||
|
||||
if (volatile is None):
|
||||
print "Flashing " + luafile
|
||||
sendCmd(s, "file.remove(\"" + luafile+"\");", True)
|
||||
if (outfile is None):
|
||||
print "Flashing " + luafile
|
||||
outfile=luafile
|
||||
else:
|
||||
print "Flashing " + luafile + " as " + outfile
|
||||
sendCmd(s, "file.remove(\"" + outfile +"\");", True)
|
||||
sendCmd(s, "w= file.writeline", True)
|
||||
sendCmd(s, "file.open(\"" + luafile + "\",\"w+\");", True)
|
||||
sendCmd(s, "file.open(\"" + outfile + "\",\"w+\");", True)
|
||||
else:
|
||||
print "Executing " + luafile + " on nodemcu"
|
||||
|
||||
@ -112,11 +116,11 @@ def main(nodeip, luafile, volatile=None):
|
||||
sys.exit(4)
|
||||
|
||||
# Check if the file exists:
|
||||
if (not sendRecv(s, "=file.exists(\"" + luafile + "\")", "true")):
|
||||
print("Cannot send " + luafile + " to the ESP")
|
||||
if (not sendRecv(s, "=file.exists(\"" + outfile + "\")", "true")):
|
||||
print("Cannot send " + outfile + " to the ESP")
|
||||
sys.exit(4)
|
||||
else:
|
||||
print("Updated " + luafile + " successfully")
|
||||
print("Updated " + outfile + " successfully")
|
||||
else:
|
||||
print("Send " + luafile + " successfully")
|
||||
|
||||
@ -131,12 +135,16 @@ if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-t', '--target', help='IP address or dns of the ESP to flash')
|
||||
parser.add_argument('-f', '--file', help='LUA file, that should be updated')
|
||||
parser.add_argument('-o', '--outfile', help='LUA file name on the microcontroller (default: same name as on host)')
|
||||
parser.add_argument('-v', '--volatile', help='File is executed at the commandline', action='store_const', const=1)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if (args.target and args.file and args.volatile):
|
||||
main(args.target, args.file, args.volatile)
|
||||
if (args.target and args.file and args.volatile and args.outfile):
|
||||
main(args.target, args.file, args.volatile, args.outfile)
|
||||
elif (args.target and args.file and args.outfile):
|
||||
main(args.target, args.file, None, args.outfile)
|
||||
elif (args.target and args.file and args.volatile):
|
||||
main(args.target, args.file, args.volatile)
|
||||
elif (args.target and args.file):
|
||||
main(args.target, args.file)
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user