Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- gpio.mode(0, gpio.OUTPUT);
- gpio.write(0,gpio.LOW);
- gpio.mode(1, gpio.OUTPUT);
- gpio.write(1,gpio.LOW);
- wifi.setmode(wifi.STATION);
- wifi.sta.config("Izya12","121788121788");
- wifi.sta.autoconnect(1);
- tmr.alarm(0, 1000, 1, function()
- ip = wifi.sta.getip();
- if ip~=nil then
- print(ip);
- tmr.stop(0);
- httpserver();
- dofile("ds1820.lua")
- else
- print("no connect");
- end
- end)
- --tmr.alarm(0, 60000, 1, function()
- -- dofile("ds1820.lua")
- --end)
- sendFileContents = function(conn, filename)
- if file.open(filename, "r") then
- --conn:send(responseHeader("200 OK","text/html"));
- repeat
- local line=file.readline();
- if line then
- conn:send(line);
- end
- until not line
- file.close();
- else
- conn:send(responseHeader("404 Not Found","text/html"));
- conn:send("Page not found");
- end
- end
- responseHeader = function(code, type)
- return "HTTP/1.1 " .. code .. "\r\nConnection: close\r\nServer: nunu-Luaweb\r\nContent-Type: " .. type .. "\r\n\r\n";
- end
- httpserver = function ()
- srv=net.createServer(net.TCP);
- srv:listen(80, function(conn)
- conn:on("receive", function(conn,request)
- print(request);
- conn:send(responseHeader("200 OK", "text/html"));
- -- conn:send("Temp:"..t1 .. "."..string.format("%04d", t2).." C\n")
- if string.find(request,"load=0") then
- gpio.write(0,gpio.HIGH);
- elseif string.find(request,"load=1") then
- gpio.write(0,gpio.LOW);
- elseif string.find(request,"load=3") then
- gpio.write(1,gpio.HIGH);
- elseif string.find(request,"load=2") then
- gpio.write(1,gpio.LOW);
- else
- sendFileContents(conn, "page.htm");
- end
- end)
- conn:on("sent", function(conn)
- conn:close();
- conn = nil;
- end)
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement