bondrogeen / dot Goto Github PK
View Code? Open in Web Editor NEWWeb server for NodeMCU ESP8266 lua
License: MIT License
Web server for NodeMCU ESP8266 lua
License: MIT License
День добрый. Подскажите пожалуйста, как сделать приветственную страницу при соединении с сервером, т.е. чтобы открывалась не форма авторизации, а страница с необходимой мне инфой ? А страницу входа в админку перенести на отдельную страницу ? Благодарю.
may be it not parse data in proper way.
Wireless client
print(uart.setup(0, 115200, 8, 0, 1, 1 ))
115200
Connect access point
IP:192.168.1.170
24560
24480
19384
22824
21624
PANIC: unprotected error in call to Lua API (web.lua:7: attempt to index a nil value)
I have this code in an .html file (and few similar lines, all not working):
<?lua local a=frj("listtitle") if a~=false then return ('<h2>Пълен списък на таговете с описание:</h2><a style="font-weight:bold;" href="fulllist.html">'..a.lt..'</a>') else return('<h2>Няма генериран списък</h2>')end?>
on dev nodemcu release all works fine, but on master branch line is displayed "as is" from the browser. Web server do not catch it to execute as lua code. Short lines works, not sure where the problem is.
Got only this message after restart in ESPlorer v0.2.0:
NodeMCU 0.9.5 build 20150318 powered by Lua 5.1.4
1
lua: init_settings.lua:1: attempt to index global 'sjson' (a nil value)
UPD:
Uploaded uncompressed file src\lua\init_settings
Error occured on string 11: "lua: init_settings.lua:11: attempt to index global 'sjson' (a nil value)".
I have found the issue, and fixed it, in order to do edit init_wifi.lua and replace:
cfg.pwd = p:len()>=8 and p or nil
with:
cfg.pwd = tostring(p):len()>=8 and p or nil
While server sending a file and you press browser refresh button, before it finish sending it. Free heap decreases with almost same size of file where it is interrupted on. If you hit several times refresh button E:M errors start to show in console or device restarts.
First I want to say, thanks for your wonderful code,
I'm a bit old style programmer, if it possible to post a simple example (without JSON and JAVASCRIPT) will be nice.
Simple form in one file and form handler (in another file) who just display what is entered in the form as _GET and _POST parameters (variables).
This probably is not server issue, but is good to be known since i face with that problem.
Long time ago you give me advice to move out calculation to javascript to prevent esp8266 from overloading, so I follow it, thank you for that.
I got one script that after loads fire XMLHttpRequest to get some data and made calculations. It was working long time, until one day, stopped working. I tried to monitor what happen. Javascript do not fire any event (load,error etc) and script froze. Web server just start serving file and close connection early,
Problem showed on firefox, chrome work as usual. After spending 1-2h, made a solution, just made a little pause before launching XMLHttpRequest and it worked. I actually do not know why it not worked, but got a suggestion that firefox try to request file in same TCP connection and that may be the problem. I may be wrong, but what I did to fix my problem is working. So it is good to be known for future developpers :)
It is rare event, but if you click on menu too fast, web server was interrupted and last coroutine is not destroyed until same file was served. To prevent this as I mention before timer was added. Here is modification what I use, so far so good:
--------- web5.lua start
`srv = net.createServer(net.TCP,10)
cr={}
tmr.alarm(5, 10000, tmr.ALARM_SEMI, function() -- it is good timer interval to match TCP timeout time
cr=nil
cr={}
end )
tmr.stop(5)
srv:listen(80,function(conn)
local cn
conn:on("receive", function(conn,payload)
tmr.stop(5)
tmr.start(5)
local req = dofile("web_request.lc")(payload)
cn=req.uri.file
cr[cn] = nil
collectgarbage()
if req
then
cr[cn] = coroutine.create(dofile("web_file.lc"))
end
if (req and req.method == "GET")
then
if coroutine.status(cr[cn]) ~= "dead"
then
local b,res = coroutine.resume(cr[cn], conn, req.uri.file, req.uri.args,req.cookie)
end
elseif req and req.method == "POST"
then
dofile("web_file.lc")(conn, req.uri.file,req.getRequestData(payload),req.cookie)
end
print(node.heap())
end)
conn:on("sent", function(conn)
if cr[cn]
then
local crStatus = coroutine.status(cr[cn])
if crStatus == "suspended"
then
local status, err = coroutine.resume(cr[cn])
if not status
then
conn:close()
cr[cn] = nil
collectgarbage()
end
elseif crStatus == "dead"
then
conn:close()
cr[cn] = nil
collectgarbage()
end
end
end)
end)
print ("[ INFO ] Web server started")`
--------------- web5.lua end
Explanation, every time when server is connected, it start a timer to delete all coroutines after 10 seconds.
If server is called inside those 10 seconds, it restart timer, so it gonna delete coroutines 10 seconds after last incoming connection. That also means server have 10 seconds to sent a file. Works for me. Makes server even more stable.
:) if you have time, gonna be nice
You know I used modified version on your web server, I received some complains from people who are unable to use it on Iphone, decided to investigate, and it do not work, reasons are unknown to me. On my modified version tried to debug it and here is the error:
PANIC: unprotected error in call to Lua API (attempt to yield across metamethod/C-call boundary)
unfortunately no line where error occur specified.
first I decide that I was one who mess the things up while modify it, downloaded your version, run it on safari (old windows version), not worked too, but error is specified:
PANIC: unprotected error in call to Lua API (web.lua:7: attempt to index a nil value)
suspect it is a headers/data parsing problem, but i'm not skilled in that direction to fix it.
I'm not a good in javascript programming, but while I edit your template start to learn a little.
Again can say "Thank you" about wonderful server and template. In the process I discovered a syntax error that usually gonna fire an error in other languages like Lua for example, in javascript it continue execution. Here is the part:
send("web_control.lua", data, function (res) {
if (res = "true") {
send("web_control.lc", {
init: "reboot"
}, function (res) {
"if (res = "true")" should have two "=" instead on one. I usually do some mistake in lua, but compiler fire and error and correct me, here it works, actually always assume res = true.
There is nothing wrong that I have seen with it, just trying to understand how it works. Do it download single file from external web server, or download multiple files. Also I take look at the code and cannot understand what "cb" do, is it a variable, function or array, where it was defined.
Hello, I'm gonna try to develop an RFID system and start looking for a proper web server, your server is great to serve static files, but after I examined the code believe it gonna fail (out of memory) if lua script is generating dynamic web content. When it sends static files, split them on 1k portions to avoid "out of memory" but if I use a lua script there is nothing that gonna prevent that. Can you implement a function or something that can be used inside lua script to send data to web client in portions to minimize memory usage?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.