Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic on request #9

Closed
Johnathan opened this issue Apr 17, 2017 · 4 comments
Closed

Panic on request #9

Johnathan opened this issue Apr 17, 2017 · 4 comments

Comments

@Johnathan
Copy link

Johnathan commented Apr 17, 2017

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
@Johnathan
Copy link
Author

Johnathan commented Apr 17, 2017

Just realised I should be hitting /api/ping, when I do that it's loading my route file ok, but it seems to be after that the panic occurs but slightly different this time

Error occured during execution: bad argument #2 to 'on' (function or lightfunction expected, got nil)
PANIC: unprotected error in call to Lua API (bad argument #2 to 'on' (function or lightfunction expected, got nil))

@loicortola
Copy link
Owner

Hi @Johnathan , I see you are using an old version of NodeMCU.
Would you be able to upgrade to NodeMCU 2.X?

@Johnathan
Copy link
Author

Yep, that's it sorted now sorry. I mistook the version of the library for the supported version of nodemcu.

Thanks for the speedy reply

@loicortola
Copy link
Owner

No worries! Glad I could be of help. Have fun with the library, your feedback is welcome if you like it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants