It takes a whole processor time and lock any other thread
This crasehs the system at all.
I try to dimm AC 230V lights by wifi commands.
Dimmig AC lights we have to use so called zero-cross detection.
Something like:
dim=0 -- lights brightness factor 0...100 (%)
-- output to control led and optotriac GPIO05
outpin=1
gpio.mode(outpin,gpio.OUTPUT)
gpio.write(outpin,gpio.LOW)
-- input from zero-cross-detect transopt GPIO04
inpin=2
gpio.mode(inpin,gpio.INT,gpio.PULLUP)
function zero_cross()
dt=((115-dim)*76)
tmr.delay(dt)
gpio.write(outpin,gpio.HIGH)
tmr.delay(150)
gpio.write(outpin,gpio.LOW)
tmr.wdclr()
return "ON"
end
gpio.trig(inpin,"up",zero_cross)
====================
It works quite well.
(except another problem with tmr.wdclr() you can find and read on another forum thread)
But... it is impossible to run wifi server at the same time like:
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive", function(client,request)
====================
Because tmr.delay occupies proccessor. Synchronize way.
When trm.delay executed , and in the same time wifi commands arrive, incidentally or not,
the system hungs up!!! When we are lucky it reboots, when nt, we have do hardware reset.
We trig tmr.delay 50 times per seconds. It's imossible to get wifi message out of the this time without life lucky.
Any idea how to fix?