--init.lua
print("set up wifi mode")
wifi.setmode(wifi.STATION)
wifi.sta.config("360WiFi-SJB","shejibu123")
wifi.sta.connect()
print("IP unavaiable, Waiting...")
tmr.alarm(1, 1000, 1, function()
if wifi.sta.getip()~= nil then
tmr.stop(1)
print("Config done, IP is "..wifi.sta.getip())
dofile("kaiguan.lua")
end
end)
--kaiguan.lua
LED=3
gpio.mode(LED,gpio.OUTPUT)
svr=net.createServer(net.TCP, 30)
function receiver(sck,data)
if (data=="ON")
then
gpio.write(LED,gpio.LOW)
sck:send("LED is ON")
else
gpio.write(LED,gpio.HIGH)
sck:send("LED is OFF")
end
print("Receive: "..data)
-- sck:close()
end
if svr then
svr:listen(80,function(conn)
conn:on("receive",receiver)
conn:send("Hell world,my LED Light")
end)
end
|