Current Lua downloadable firmware will be posted here

User avatar
By cendev
#2582
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 :D You will call it whenever you want to upload a file :)

Code: Select all    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
Code: Select all#!/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 :)
User avatar
By xinort
#2585 I'm not sure if this is the best place to ask this but I'm using the lua web server and running into a problem. I can connect but only 2 times before I get a MAX_SOCKET error. I can't figure out how to release the socket after sending the data. I've tried conn:close() but no joy. This is the lua script I'm trying to use:

Code: Select allsrv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive",function(conn,payload)
print(payload)
door="open"
if gpio.read(8)==1 then door="open" else door="closed" end
conn:send("<h1> Door Sensor. The door is " .. door ..".</h1>")
conn:close()
end)
end)
User avatar
By zeroday
#2588
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)?


Sorry for my misunderstanding, A simple IDE with lua editor and serial console is under development.