Current Lua downloadable firmware will be posted here

User avatar
By tatulea
#11042 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?
User avatar
By dpwhittaker
#11328 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.
User avatar
By cal
#12191 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