카테고리 없음2016. 7. 24. 21:16

http://kocoafab.cc/tutorial/view/592

댓글에 보면 ESP8266을 아두이노처럼 쓰게 해준다는 Wemos D1 얘기가 나옴


출처 : http://deneb21.tistory.com/407


-- a simple HTTP server

srv = net.createServer(net.TCP)
srv:listen(80, function(conn)
    conn:on("receive", function(sck, payload)
        print(payload)
        sck:send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<h1> Hello, NodeMCU.</h1>")
    end)
    conn:on("sent", function(sck) sck:close() end)
end)



위 예제를 따라하면 아래와 같은 에러가 날 수 있다


unprotected error in call to Lua API (webserver.lua:2: only one tcp server allowed)


구글에서 찾아보니 기존에 열려 있는 서버가 있어서 발생하는 문제임

아래 싸이트에 나온것 처럼 기존 서버를 닫아주고 다시 열면 문제가 없음


http://stackoverflow.com/questions/37566185/only-one-tcp-server-allowed-esp8266-with-lua


if srv~=nil then
  srv:close()
end

srv = net.createServer(net.TCP)
srv:listen(80, function(conn)
    conn:on("receive", function(sck, payload)
        print(payload)
        sck:send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<h1> Hello, NodeMCU.</h1>")
    end)
    conn:on("sent", function(sck) sck:close() end)
end)




Posted by orasman