I have the same problem. A gpio.read() does pull down in hardware, but returns the right value in software (high/low).
And the gpio.mode(pin,gpio.OUTPUT,1) does nothing to fix that problem.
Will have to use a variable to save the state until gpio.read() is fixed..
This example script found on this site will crash the mcu when performing gpio.read().
Code: Select alls=net.createServer(net.TCP)
s:listen(80,function(c)
c:on("receive",function(c,pl)
for v,i in pairs {8,9} do
gpio.mode(i,gpio.OUTPUT,1)
c:send("\ngpio("..i.."):"..gpio.read(i))
if string.find(pl,"gpio"..i.."=0") then gpio.write(i,0) end
if string.find(pl,"gpio"..i.."=1") then gpio.write(i,1) end
c:send("\nnew_gpio("..i.."):"..gpio.read(i))
end
c:send("\nTMR:"..tmr.now().." MEM:"..node.heap().."\n")
c:on("sent",function(c) c:close() end)
end)
end)
To have this code run I must comment out the lines involving read.
Code: Select all>> c:on("sent",function(c) c:close() end)
>> end)
>> end)
> H????19@H?DHJ??@H?
NodeMcu 0.9.2 build 20141209 powered by Lua 5.1.4
lua: cannot open init.lua
>
Output from sending curl "10.0.xx.xx/gpio8=1" to module.