Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ssid = "DSPLAB"
- pass = "feriiot123!"
- wifi.setmode(wifi.STATION)
- print('set mode=STATION (mode=' .. wifi.getmode()..')\n')
- print('MAC Address: ',wifi.sta.getmac())
- print('Chip ID: ',node.chipid())
- wifi.sta.config(ssid,pass)
- wifi.sta.connect()
- relay2 = 3
- relay1 = 2
- tmr.alarm(1, 1000, 1, function()
- if wifi.sta.getip() == nil then
- print("IP unavaiable, Waiting...")
- else
- tmr.stop(1)
- print("ESP8266 mode is: " .. wifi.getmode())
- print("The module MAC address is: " .. wifi.ap.getmac())
- print("Config done, IP is "..wifi.sta.getip())
- end
- end)
- print(wifi.sta.getip())
- srv=net.createServer(net.TCP)
- srv:listen(80,function(conn)
- conn:on("receive",function(conn,payload)
- print("PAYLOAD " .. payload)
- if(string.match(payload,"/temp")) then
- t = require("ds18b20")
- t.setup(1)
- temperatura = t.read()
- print(t.read())
- conn:send("HTTP/1.1 200 OK\r\n\r\n"..temperatura)
- end
- if(string.match(payload,"/hum")) then
- conn:send("HTTP/1.1 200 OK\r\n\r\n")
- end
- if(string.match(payload,"/rgb/off"))then
- conn:send("HTTP/1.1 200 OK\r\n\r\n")
- end
- if(string.match(payload,"/rgb/color?"))then
- r,g,b= payload:match("R=(%d+)&G=(%d+)&B=(%d+)")
- print (r,g,b)
- conn:send("HTTP/1.1 200 OK\r\n\r\n")
- --NASTAVI BARVO, GLEDE NA PARAMETRE R G B
- --IF SUCCESSFUL
- conn:send("HTTP/1.1 200 OK\r\n\r\n")
- end
- if(string.match(payload,"/relay1/on"))then
- conn:send("HTTP/1.1 200 OK\r\n\r\n")
- gpio.write(relay1, gpio.HIGH)
- end
- if(string.match(payload,"/relay1/off"))then
- conn:send("HTTP/1.1 200 OK\r\n\r\n")
- if(pcall(gpio.write(relay1, gpio.LOW))then
- conn:send("OK");
- end
- end
- if(string.match(payload,"/relay2/on"))then
- gpio.write(relay2, gpio.HIGH)
- conn:send("HTTP/1.1 200 OK\r\n\r\n")
- end
- if(string.match(payload,"/relay2/off"))then
- gpio.write(relay2, gpio.LOW)
- conn:send("HTTP/1.1 200 OK\r\n\r\n")
- end
- end)
- conn:on("sent",function(conn) conn:close() end)
- t = nil
- ds18b20 = nil
- package.loaded["ds18b20"]=nil
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement