Coder Social home page Coder Social logo

loicortola / nodemcu-espress Goto Github PK

View Code? Open in Web Editor NEW
37.0 37.0 9.0 217 KB

Ultra-Lightweight and modular Node.js express like http server for NodeMCU. web - ESP8266

License: MIT License

Lua 75.98% Shell 16.29% Batchfile 7.73%
api http http-server node nodemcu server static

nodemcu-espress's People

Contributors

loicortola avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nodemcu-espress's Issues

Serving static gz files

Please add a mime for serving gzipped static files. This would help serving a compressed JavaScript library.

Panic on Post

Hi!
I'm trying to make a relay controller
My relay.post.lua: http://pastebin.com/m3nQ5mZE
and my index.html: http://pastebin.com/3TBJaDsD
I'm getting

Begin Http request: 29536
Connection initialized with id 263
Request callbacks have been set: 29104
PANIC: unprotected error in call to Lua API (bad argument #2 to 'on' (function or lightfunction expected, got nil))

Where i'm wrong?

Panic on request

Similar to #7 and #4

Issue happens when I make a GET request to /ping

NodeMCU 1.5.4.1 build unspecified powered by Lua 5.1.4 on SDK 1.5.4.1(39cb9a32)
In handler routes_auto.lc
Next handler http_default_handler.lc will be after routes_auto.lc
Server listening on port 80
Available memory is 26848 bytes.
> Begin Http request
Connection initialized with id 691
Request callbacks have been set. Available memory: 27632 bytes
Processing element 691
Request received: 	GET	/ping
Error occured during execution: ?:0: attempt to concatenate a nil value
PANIC: unprotected error in call to Lua API (bad argument #2 to 'on' (function or lightfunction expected, got nil))

List of uploaded files

	  |- init.lua (365 Bytes)
	  |- http-404 (19 Bytes)
	  |- http-302 (26 Bytes)
	  |- http_default_handler.lc (180 Bytes)
	  |- http_response_sendfile.lc (1536 Bytes)
	  |- espress_init.lc (1680 Bytes)
	  |- routes_auto.lc (932 Bytes)
	  |- http-200 (12 Bytes)
	  |- routes/ping.get.lc (280 Bytes)
	  |- router.lc (864 Bytes)
	  |- http-405 (27 Bytes)
	  |- http_request.lc (660 Bytes)
	  |- http-401 (21 Bytes)
	  |- http_response.lc (520 Bytes)
	  |- espress.lc (2860 Bytes)
	  |- http-400 (20 Bytes)
	  |- http_request_buffer.lc (680 Bytes)
	  |- http_prototypes.lc (944 Bytes)
	  |- ping.get.lc (248 Bytes)
	  |- http_request_processor.lc (672 Bytes)
	  |- http_response_send.lc (748 Bytes)
	  |- type-json (40 Bytes)
	  |- http-503 (28 Bytes)
	  |- http-500 (30 Bytes)
	  |- http-403 (18 Bytes)
	  |- http_getondata.lc (472 Bytes)
	  |- auth_api_key.lc (756 Bytes)

init.lua

espress = require 'espress'

function initialConnection()
    wifi.setmode(wifi.STATIONAP)

    -- Setup as Access Point
    wifi.ap.config({
        ssid = "Hame-Hue-Switch",
        pwd = "hamepassword",
        auth = wifi.OPEN
    })

    local server = espress.createserver();

    server:use("routes_auto.lc")

    server:listen(80);
end

initialConnection()

routes/ping.get.lua

return function(req, res)
    res:addheader("Content-Type", "application/json; charset=utf-8")
    res:send("{device: \Light Switch\"}")
end

NodeMCU modules requirements

Hello, first of anything, thanks for the great work, it seems great and I'm planning on use it for a project. However I'm having some issues using some of the samples provided in the repo.

Trying to run the simple-website-with-forms sample I'm getting all the values as nil, so I would like to know if there is some node mcu modules needed as prerequisites to use nodemcu-espress properly. Thanks in advance.

use model as a lua module makes unloading difficult

The webserver is loaded as a lua module via a require. While this makes the code more elegant, it also makes it necessary to jump through hoops to unload the lua module (consider the accepted answer here, where the developer of jitlua says there is no reliable way. In larger systems, such as a laptop or game console, it is ok to load modules in that way, but I think it is not very suited to a small embedded application like the ESP.
Examle cases where the module would need to be unloaded in the ESP are, among others:
*if the server were to be disabled
*in case of a mutiprotocol TCP server, which is my usage case

Instead, I suggest switching to a dofile() and returning an object or a function. If no longer needed, the object could just be niled to release and allow gc.

Personally, I prefer to separate the TCP socket server from the http server. This can be done by implementing a dofile() that returns 3 functions: a detector, an installer, and the onReceive callback. Consider the implementation here, file tcpserver.lua.

No mimi-type for .ICO files

My browser always requests /favico.ico. The mime-type is not in the mime-types directory.

the file mime-types/type-ico should contain return "image/x-icon"

Panic on request

I tried the simple-api demo as described. The api-key is turned of.

local espress = require 'espress'
local port = 80
local server = espress.createserver(port)
server:use("routes_auto.lc")

The nodemcu crashes with this message:

Request received: GET /api/hello
routes/hello.get.lc
PANIC: unprotected error in call to Lua API (?:0: attempt to call a nil value)

Tested firmware is the newest version from http://nodemcu-build.com/ master build with modules: bit, crypto, file, gpio, net, node, tmr, uart, wifi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.