Chat about current Lua tools and IDEs

User avatar
By JumpZero
#68820 Hi
Your software is actually very good!
It's the simplest and easiest way to upload file OTA I found after googling for 1 hour. (Anybody knows something else?)
But.. Can we have an Linux/ARM version (for Raspberry Pi)
or a Linux x86 32 bits
or source code to compile myself

Thanks for your good work
--
Jmp0
PS: no Windows in this home, no Linux 64, only Raspberries, arduino, ESP8266 and old Linux32 laptop
User avatar
By JumpZero
#68880 I actually found this script
https://github.com/balu-/nodemcu-telnet-uploader
to upload files OTA
But it wasn't working very well, I did some improvements, I found it ok for my needs:

README.txt
============
Code: Select all---Guy---August 2017
--------------------
Original script come from
https://github.com/balu-/nodemcu-telnet-uploader
improvement done:
1- removing the comment following the shebang #!/usr/bin/expect
   it is causing the expect command to fail
2- file.open() doesn't return true or false anymore but an object
   IMHO this is a NodeMCU firmware change.
   script modified accordingly
3- The original script fails to upload big files (around 100 lines)
   This is due to a ESP restart during transfer. IMHO heap/memory
   problem. To avoid this I modify the script to send batch of
   60 lines (arbitrary choice) only. So I use the a+ instead of
   w+ when opening the file (append mode). Send batch of 60 lines
   flush, close and start again.
   To achieve this there is a wrapper bash script calling the
   expect script. expect script renamed NodeMcuTelnetUploaderByBatch
   (from uload.sh) and wrapper script is NodeMcuTelnetUploader

Usage:
NodeMcuTelnetUploader <NodeMcu IP> <port> <Dest. file> <Source file>

Make sure the file <Dest. file> doesn't exist before transfer
because it doesn't overwrite but append.


NodeMcuTelnetUploaderByBatch
================================

Code: Select all#!/usr/bin/expect -f
#If it all goes pear shaped the script will timeout after 20 seconds.
set timeout 20
#First argument is assigned to the variable ip
set ip [lindex $argv 0]
#Second argument is assigned to the variable port
set port [lindex $argv 1]
#Third argument is assigned to the variable filename
set remotefilename [lindex $argv 2]
set filename [lindex $argv 3]
#prep file content
set fp [open "$filename" r]
set file_data [read -nonewline $fp]
close $fp
#  Process data file
set data [split $file_data "\n"]
#This spawns the telnet program and connects it to the variable ip
spawn telnet $ip $port
#The script expects login
#expect "Connected to $ip."
expect "Escape character is '^]'."
sleep 1
# Modif Guy. Try: change w+ to a+ on file open and send file by smaller blocks
# + file.open() doesn't return true or false anymore but an object
# send "if true == file.open(\"$remotefilename\", \"w+\") then \r"
send "if nil ~= file.open(\"$remotefilename\", \"a+\") then \r"
expect ">>"
send "print(\"ok\")\r"
expect ">>"
send "end\r"
expect "ok"
foreach line $data {
          # do some line processing here
          expect ">"
          #replace all ' with \'
          regsub -all {\\r} $line {\\\\r} line
          regsub -all {\\n} $line {\\\\n} line
          regsub -all {'} $line {\\'} line
          puts "writing $line"
          send "if true == file.writeline('$line') then \r"
        expect ">>"
        send "print(\"ok\")\r"
        expect ">>"
        send "end\r"
        expect "ok"
}
expect ">"
send "file.flush()\r"
expect ">"
send "file.close()\r"
expect ">"
send "print(\"done\")\r"
expect "done"
sleep 1
close
#This hands control of the keyboard over two you (Nice expect feature!)
#interact


NodeMcuTelnetUploader
================================
Code: Select all#!/bin/bash
# Guy August 2017
#

if [ $# -lt 4 ]; then
  echo "Usage = $0 <NodeMcu IP address> <Telnet port> <Destination file> <Source file>"
  exit
fi

# Let's split the file to send by blocks of 60 lines (arbitray choice)
split --lines=60 $4 /tmp/TmpFile

echo "Here are the temporary files we are going to send"
ls -l /tmp/TmpFile*

let "NumberOfFile=`ls -l /tmp/TmpFile* | wc -l`"
echo "Number of files to send = $NumberOfFile"

for i in {a..z} # 26 files max should be enough ;-)
do
  if [ -e /tmp/TmpFilea$i ]; then
    echo -e "\033[32mTransfer of /tmp/TmpFilea$i\033[0m"
    # The 2 scripts must be in the same folder (the working dir)
    ./NodeMcuTelnetUploaderByBatch $1 $2 $3 /tmp/TmpFilea$i
    echo -e "\033[32mTransfer done\033[0m"
    sleep 1
  fi
done

echo -e "\033[32mALL TRANSFERS DONE !"
echo "Removing temporary files"
rm /tmp/TmpFile*
echo -e "END\033[0m"


It may help others,
simple but do the job
--
Jmp0
User avatar
By enaon
#68983
JumpZero wrote:(Anybody knows something else?)



espresso is really nice, the binary upload feature is very useful for uploading sound files :)

Nevertheless you gave me the motivation to upload my scripts on gist. I had the same problem, wanted to update esp over the air, and I do have a way that works good and is fast, although a bit too customized maybe.

If you care to have a go, the part that deals with recover mode for uploading files is here.

https://gist.github.com/enaon
User avatar
By JumpZero
#69045 Hi Enaon,
Sure I will give a try. I have read your code and I look forward testing it. When I I'm back home (currently on vacation :-)
Although I would try your original, the one in the other post: "simple file over network", as you said the one on git is very customized for a first test.
I'll be back
--
Jmp0