Last active
August 29, 2015 14:15
-
-
Save saihtaM/35681a39385fbbd92974 to your computer and use it in GitHub Desktop.
My ESP8266 NodeMcu Lua scripts.. I'll just usually only use init.lua, but you can do whatever you want.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- GET request on input, https://gist.github.com/saihtaM/35681a39385fbbd92974 | |
-- I use this on my doorbell, but I have a little mic module that returns 3V on GPIO2 when a high sound is detected. That little mic module is hidden inside the doorbell. | |
-- This way, if the power is out. My doorbell stil works, and I don't have to think about killing my ESP8266 due to the voltage spikes that my doorbell is so happy to spit out (according to my multimeter). | |
pin = 4 -- 3 = GPIO0, 4 = GPIO2 | |
firstrun = true | |
gpio.mode(pin,gpio.INPUT) | |
function pinsendrequest() | |
print("Sending request") | |
conn=net.createConnection(net.TCP, false) | |
conn:on("receive", function(conn, pl) print(pl) end) | |
conn:connect(80,"192.168.1.2") | |
conn:send("GET /esp8266_control.php?what=ESP01Doorbell HTTP/1.1\r\nHost: replace.if.needed\r\n" | |
.."Connection: keep-alive\r\nAccept: */*\r\n\r\n") | |
conn:send("\r\n") | |
end | |
gpio.trig(pin, "up", pinsendrequest) | |
function checkip() | |
if wifi.sta.getip() == nil then | |
print "I have no ip..." -- This also makes the little blue LED flash, so you can see when your WiFi is gone. | |
else | |
if firstrun == true then | |
print(wifi.sta.getip()) | |
pinsendrequest(1) | |
firstrun = false | |
end | |
end | |
end | |
tmr.alarm(5, 1000, 1, checkip) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment