Post your best Lua script examples here

User avatar
By fikin
#68814 this is for those of us, interested in more unit testing the code before uploading it to nodemcu.

i've began sketching a simulated implementation of nodemcu api, where callbacks would be working reasonably well and one can control time and data traffic.

one has to clone https://github.com/fikin/nodemcu-lua-mocks and include the files in its own project.
and btw, feel most welcome to help make it better.

here is how one can test alarm:
Code: Select allrequire('tmr')
local fired = false
tmr.create(1,tmr.ALARM_SINGLE,function(timerObj)
   fired = true
end):start()
Timer.joinAll(2) -- advance time with 2ms
luaunit.assertTrue(fired)


there is already reasonably well working implementation for wifi, net, gpio, adc and few more.