gerardwr wrote:zeroday wrote:If you want to run something when system started
<snip>
and use dofile, require ets to load other file in init.lua
Yes, I understand that you can create the file lua.init that is started at boottime. Did that, works.
Yes, I understand that you start an other lua command file with dofile.
No, I do NOT understand what you mean with "require ets to load other file in init.lua", and how this helps in uploading a script to the ESP.
You have pointed out that you hope that many lua scripts will be developed for your platform. Nobody will want to type the lines of these scripts line-by-line in the terminal. Surely you have an idea (or procedure) how to upload these scripts.
Call me stupid, but I repeat my previous question : " How can I upload a textfile on my PC containing a lua script to a file on the ESP (to init.lua for example)?
First you must create a lua script on esp You will call it whenever you want to upload a file
file.open("server.lua","w+")
s=net.createServer(net.TCP)
s:listen(8888,function(c) c:on("receive",function(c,pl) print(pl) pcall(loadstring(pl)) end) end)
file.close()
After you dofile("server.lua") and start server on esp you can call this python file
You can improve this This one can be used as
python upload.py createfilename.lua filetoupload.lua 192.168.1.3 8888
#!/usr/bin/env python
import socket
import time
import sys
toCreate = str(sys.argv[1])
toUpload = str(sys.argv[2])
ip = str(sys.argv[3])
port = str(sys.argv[4])
TCP_IP = ip
TCP_PORT = int(port)
BUFFER_SIZE = 1024
time.sleep(1)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
s.send("file.open(\"%s\",\"w+\")" %(toCreate,))
time.sleep(0.1)
with open(toUpload) as f:
for line in f:
print(line)
s.send("file.writeline([[%s]])" % line)
time.sleep(0.1)
s.send("file.close()")
s.close()
Edit : Corrected but still lacks of control functions (is connected? all args set ? server recieved?... etc ..)
Soon when i have some free time i'll create a C# app which will have a browser for files , simple file operations(upload, read, copy, rename, edit..) and some other functions It's been a long time since i've used windows or VS