Chat about current Lua tools and IDEs

User avatar
By kirsch
#10456 Hello,

I just posted my generic web server for NodeMCU: https://github.com/marcoskirsch/nodemcu ... ree/master
It is pretty basic: Will serve static files and only supports GET, but it also supports running dynamic scripts so you can make it do a lot without dealing with server logic yourselves.

Memory is tight, so node.compile the file after uploading and if that fails, you may need a build of the firmware with no floating point.

I'm looking forward for feedback and to hear how people are using it.
Attachments
Screen Shot 2015-02-22 at 4.53.53 PM.png
User avatar
By dpwhittaker
#10476 Couple of issues here:

If you conn:send more than 1460 bytes without waiting for the "sent" callback, you will eventually overflow the internal buffers. I think the buffer will actually hold 2 packets, but 2920 bytes is still not a lot, especially if you want to serve images. I use coroutines to yield execution until the callback is called.

If you start handling post, you can get multiple receive callbacks, one per packet. Either way, closing the connection in onReceive will not take you very far.

You can save some heap by combining parseRequest and parseUri into a single regular expression. string.match can can match \r\n.

See my post in Script Examples "My take on the lhttpd port" for some more ideas... we're basically trying to do the same thing. Mine handles post, images, server templates (through pre-compilation to .lua files), and large files. Memory is tight, but it seems to be working for a decently useful application (a web-based ide). Take a look at the code in the dropbox link, but be warned it is in heavy development.
User avatar
By kirsch
#10721 This is great, I appreciate the feedback.
I will look into the sent callback. In my tests I never saw it invoked and didn't really understand why. But I did try to serve up a 7KB gif and it died halfway through. May be related.

You can save some heap by combining parseRequest and parseUri into a single regular expression. string.match can can match \r\n.


Yes, this is in my TODOs. I'll try this as well. Memory is extremely tight and I'd like this to run on the firmware build that has floating point enabled, which it currently cannot.
User avatar
By kirsch
#11010 I just pushed changes to the server: https://github.com/marcoskirsch/nodemcu-httpserver
As suggested by @dpwhittaker I now serve files from a separate thread in chunks yielding after each one, then resuming on the "sent" callback. I can now serve large files like images! :mrgreen: Thanks for the suggestion.

I also did some more refactoring and moved sine code to separate files. I'm hoping this helps with memory. If someone tries it on a nodemcu build with floating point enabled I'd love to hear (and I will update README.md).

Other suggestions, tips, pull requests are welcome.