frightanic.com의 NodeMCU 사용자 빌드를 사용하여 lua로 ESP8266에서 로컬 http 서버를 만들려고합니다.패닉 : Lua API (wificonfig.lua : 33 : 사용중인 주소)에 대한 보호되지 않은 오류
포트 80에서 이미 수신 대기중인 연결과 로컬 http 서버를 만들고 서버 사이트에서 데이터를 가져 오는 경우 PANIC 오류가 발생합니다.
wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","password")
wifi.sta.connect()
tmr.alarm(1,10000, 1, function()
if (wifi.sta.getip() == nil) then
print("IP unavaiable, Waiting...")
else
foo()
local_server()
end
end)
function foo()
conn = nil
conn=net.createConnection(net.TCP,0)
conn:on("receive", function(conn, payload)
print("payload : "..#payload);
end)
conn:connect(80,"server.co.in")
conn:on("connection", function(conn, payload)
conn:send("GET /mypage?id=deadbeef HTTP/1.0\r\nHost: server.co.in\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n") end)
conn:on("sent",function(conn)
print("Closing server connection")
conn:close()
end)
end
function local_server()
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive", function(client,request)
local buf = "Hello world";
client:send('HTTP/1.0\n\n')
client:send('<!DOCTYPE HTML>\n')
client:send('<html>\n')
client:send('<head><meta content="text/html; charset=utf-8">\n')
client:send('<title>Local server</title></head>\n')
client:send('<style>body{ background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }</style>\n";')
client:send(buf);
conn:on("sent",function(conn)
srv:close() -- Even tried with client:close()
end)
end)
end)
end
는이 작업을 수행 할 수 없습니다 :
여기 내 코드입니까? 그렇다면 어떻게 할 수 있습니까?
타이머를 서버에 한 번만 만들면 모든 로컬 서버가 생성되지 않습니다. 로컬 서버 192.168.x.y를 열 수 없습니다.
wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","password")
wifi.sta.connect()
tmr.alarm(1,10000, 1, function()
if (wifi.sta.getip() == nil) then
print("IP unavaiable, Waiting...")
else
print("Creating a server");
srv=net.createServer(net.TCP,0)
srv:listen(80,function(conn)
end)
tmr.stop(1)
tmr.alarm(1,10000, 1, function()
foo()
local_server()
end)
end
end)
function foo()
conn = nil
conn=net.createConnection(net.TCP,0)
conn:on("receive", function(conn, payload)
print("payload : "..#payload);
end)
conn:connect(80,"server.co.in")
conn:on("connection", function(conn, payload)
conn:send("GET /mypage?id=deadbeef HTTP/1.0\r\nHost: server.co.in\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n") end)
conn:on("sent",function(conn)
print("Closing server connection")
conn:close()
end)
end
function local_server()
conn:on("receive", function(client,request)
local buf = "Hello world";
client:send('HTTP/1.0\n\n')
client:send('<!DOCTYPE HTML>\n')
client:send('<html>\n')
client:send('<head><meta content="text/html; charset=utf-8">\n')
client:send('<title>Local server</title></head>\n')
client:send('<style>body{ background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }</style>\n";')
client:send(buf);
conn:on("sent",function(conn)
srv:close() -- Even tried with client:close()
end)
end)
end
처음에는 HTTP/1.0 200 ok 자체를 사용했지만 HTTP/1.0으로 시도하는 것보다 작동하지 않는 경우가 많았습니다. 오류가 참조하는 주소는 내 WiFi 모듈 (액세스 포인트에 연결된 스테이션으로 작동)의 IP 주소이거나 다른 주소입니까? 내 코드에서 볼 수 있듯이 포트 80에서 클라이언트 연결을 열었습니다. 그런 다음 close.conn : connect (80, "server.co.in") – aditgupta100
나는 다른 포트를 듣고 시도했습니다. 9999 하지만 같은 오류가 발생했습니다. – aditgupta100
오류 메시지가 귀하의 WiFi 모듈에 대해 로컬임을 나타냅니다. 먼저 코드를 단순화하는 것이 좋습니다. 즉, 서버 만 구현하면됩니다. –