ESP8266

Aus Wiki CCC Göttingen
Zur Navigation springen Zur Suche springen

ESP8266 is a complete and self-contained Wi-Fi network chip.

<highlightSyntax language="lua">

require('ds18b20')

port = 80

gpio0, gpio2 = 3, 4 ds18b20.setup(gpio2)

t=""

gpio.mode(gpio0,gpio.OUTPUT)


for i=1,10 do gpio.write(gpio0,gpio.LOW); tmr.delay(100000) gpio.write(gpio0,gpio.HIGH); tmr.delay(100000) end

ip = wifi.sta.getip() print (ip)

if ( ip == nil ) then

 while 1 do    
     gpio.write(gpio0,gpio.LOW);
     tmr.delay(50000)
     gpio.write(gpio0,gpio.HIGH);
     tmr.delay(50000)
 end
 node.restart()

end


srv=net.createServer(net.TCP) srv:listen(port, function(conn) conn:on("receive",function(conn,request) local buf = ""; local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP"); if(method == nil)then _, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP"); end local _GET = {} if (vars ~= nil)then for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do _GET[k] = v end end if (_GET.pin == "on")then gpio.write(gpio0,gpio.LOW); elseif(_GET.pin == "off")then gpio.write(gpio0,gpio.HIGH); end print(node.heap()) t = ds18b20.read()

         	conn:send("HTTP/1.1 200 OK\nContent-Type: text/html\n\n" ..
             		"<!DOCTYPE HTML>" ..
             		"<html><body>" ..
             		"Temperature : " .. t .. "
" .. "</html></body>") end)

conn:on("sent",function(conn) conn:close() end) collectgarbage("collect") end)

</highlightSyntax>