-->
Page 1 of 1

LUA question

PostPosted: Sun Mar 01, 2015 2:22 pm
by tatulea
Hello! I am using NodeMCU firmware and I want to make this:
1.Create a server (done)
2.Listen the server (done)
3.Send data to uart after server:listen() (done)
4.Waiting for an answer from uart (here is the problem)

How can I waiting for the answer?

Re: LUA question

PostPosted: Wed Mar 04, 2015 8:12 pm
by dpwhittaker
https://github.com/nodemcu/nodemcu-firm ... _en#uarton

uart.on("data", n, func, 0)

Where n is the number of characters (or character to read until, I.e. \n), and func is a function that takes a single string that represents the data received.

Define that function inside your listen function and it will have access to the connection parameter to send results back to the browser. Then you can define uart.on("sent", function() conn:close() end) inside the on data event to finally close the connection after you've sent the last of the data.

You just have to get used to the event-driven, callback-oriented programming style.

Re: LUA question - HTTP server multi threaded?

PostPosted: Wed Mar 18, 2015 11:01 am
by cal
Hi!

Is the lua HTTP-Server single threaded, means only one person can request a page at a time?
If yes it's a strange HTTP-Server but the suggestion will work.

If concurrent accesses are possible:
Does UART.on cope with concurrent running threads?

I don't find anything about concurrency for nodemcu or did I miss something?

Thanks!

Cal