Chat about current Lua tools and IDEs
User avatar
By enaon
#20051 Hello,

this is a simple q&d solution that enables me to send files over the network to my esp. It is supposed to be helpful in situations where one is testing code in a esp connected to the uart using maybe luauploader, and when he is happy with the results, he can then send them to another esp over the air.

The code that goes to the esp is the following:
Code: Select allupload=nill

 c:on("receive", function(c, fileName)
-- print(fileName)
    if (fileName=="file_upload_start")then
        c:send("**enter the file name**\n")
        print("**file upload started**")
    elseif (fileName=="file_upload_stop")then
        c:send("**file "..savedFile.." saved**\n")
        c:send("heap :"..node.heap().."\n")
        print("\n\r**file "..savedFile.." saved**")
        print("heap :"..node.heap())
    elseif (upload_mode==1)then
        c:send("**opened file "..fileName.." for writing**\n")
        c:send("heap :"..node.heap().."\n")
        print("**opened file "..fileName.." for writing**")
        print("heap :"..node.heap().."\n")
        file.remove(fileName), "w+")
    elseif (upload_mode==2)then
       print(fileName.." >> " ..savedFile)



you upload it to the esp, then call it by dofile("m_upload.lua") (or lc if you compile it) and it listens on port 88
for a connection from the pc

You can then use this script on linux (netcat is needed)

save it as an sh in the same folder as your lua scripts(chmode +x and call it using the filename.lua and the ip of the remote esp as arguments, like so test.lua
Code: Select all#!/bin/bash
echo -n file_upload_start | nc -w 1  $2 88
echo  -n $1 | nc  -w 1  $2 88
echo ""
#while read -r x; do sleep 0.2; echo "$x"; echo -n "$x" | nc -w 1 $2 88 ; done < $1
while read -r x; do sleep 0.2; echo -n $x | nc -w 1 $2 88 ; done < $1
echo ""
echo -n file_upload_stop | nc -w 2  $2 88

from windows use the following 2 files:

uploadtoesp.bat (again call it like uploadtoesp.bat XXX.lua X.X.X.X)
Code: Select all@echo off
echo | set /p dummyName="file_upload_start" | nc.exe -w 1  %2 88
echo | set /p dummyName="%1" | nc.exe  -w 1  %2 88
nc.exe -e "parse.bat %1"  %2 88
type %1
echo | set /p dummyName="file_upload_stop"  | nc.exe -w 1  %2 88

Code: Select all@echo off
set wait=50
echo wscript.sleep %wait% > wait.vbs
for /F "delims=" %%a in (%1) do ( echo | set /p dummyName=%%a
wscript.exe wait.vbs )
del wait.vbs

you will again neet to place them where you keep your lua script, or adjust the path.

you will also need nc for windows.