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