-->
Page 1 of 1

Can my script get better

PostPosted: Sun Mar 15, 2015 12:53 am
by swilson
Got a simple little lua script running on a esp-12 to detect interrupt (high, low) on gpio5. Should I take my wifi settings and put them in init.lua or will it work better where they are. If you guys have any suggested changes or questions please let me know. PS: I am a newb at coding these but they are too fun not to learn.

Code: Select alllocal pin = 2
function pin1cb(level)
tmr.delay(1000)

--wifi.setmode(wifi.STATION)
--wifi.sta.config("myssid","mypassword")
tmr.delay(5000)
print(wifi.sta.getip())

conn=nil
conn=net.createConnection(net.TCP, 0)
   conn:on("receive", function(conn, payload)
       print(payload)
       end)

conn:on("connection", function(conn,payload)
conn:send("HELO mail.xxxxxxxxxx.net\r\n")
conn:send("MAIL FROM:myemail@gmail.com\r\n")
conn:send("RCPT TO:mycellnumber@vtext.com\r\n")
conn:send("RCPT TO:myemail@gmail.com\r\n")
conn:send("Data\r\n")
conn:send("Subject: GENERATOR ALERT!!!\r\n")
if level == 1 then
conn:send("Generator at the OLD HE is running!\r\n")
print("Generator running!!")
else
conn:send("Generator at the OLD HE has shut down!\r\n")
print("Generator shut down!!")
end
conn:send(".\r\n")
conn:send("quit")

end)

conn:connect(25,"x.x.x.x")
if level == 1 then gpio.trig(1, "down ") else gpio.trig(1, "up ") end
    end
gpio.mode(2, gpio.INT)
gpio.trig(2, 'both',pin1cb)