This will be my first post, not sure if posting in correct topic.
I have connected PIR element to ESP chip to GPIO2 port, PIR uses external +5V source. When both connected esp fails to start, if you plug out pir output form gpio2 then it start and again reconnecting with pir output works.
The PIR chip is SR501. I don't understand what i am doing here wrong. Can i handle it in code? Or should i...like create port waiting, or checking if files already ...or add a button to say, it is ok to run scripts...
And the second question: for some reason UP flag does not work, so had to use down, basically at this elements configuration it does not matter. But for what reason when specified UP, trigger does not trigger. is it firware problem?
or wrong usage of code?
A firmware used:
https://github.com/nodemcu/nodemcu-firm ... v_20150704 (integer)
(or should i use different firmware?)
Here is my code:
Init.Lua ->
print("Setting up WIFI...")
wifi.setmode(wifi.STATION)
wifi.sta.config("#####","?????")
wifi.sta.connect()
tmr.alarm(1, 1000, 1, function()
if wifi.sta.getip()== nil then
print("IP unavaiable, Waiting...")
else
tmr.stop(1)
print("Config done, IP is "..wifi.sta.getip())
dofile("pirSensorDataTransmitter.lua")
end
end)pirSensorDataTransmitter.lua ->
pirSensorPIN = 4
gpio.mode(pirSensorPIN, gpio.INT)
gpio.trig(pirSensorPIN, 'down', sendData)
function sendData()
--if (gpio.read(pirSensorPIN) == gpio.LOW) return;
conn= net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) print(payload) end)
conn:connect(80,'184.106.153.149')
conn:send("GET /update?key=#######??????####\r\n")
conn:send("Host: api.thingspeak.com\r\n")
conn:send("Accept: */*\r\n")
conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n")
conn:send("\r\n")
conn:on("sent",function(conn)
print("Closing connection")
conn:close()
end)
conn:on("disconnection", function(conn)
print("Got disconnection...")
end)
end