如何使用集成了ESP8266芯片的NodeMCU以配置一个可交互的TCP服务器

如题所述

第1个回答  2016-06-27
https://github.com/nodemcu/nodemcu-firmware/blob/master/lua_examples/http-client.lua

看示例代码,实现一个http服务器,至于交互什么,要看你的需求~

-- Support HTTP and HTTPS, For example
-- HTTP POST Example with JSON header and body
http.post("http://somewhere.acceptjson.com/",
"Content-Type: application/json\r\n",
"{\"hello\":\"world\"}",
function(code, data)
print(code)
print(data)
end)

-- HTTPS GET Example with NULL header
http.get("https://www.vowstar.com/nodemcu/","",
function(code, data)
print(code)
print(data)
end)
-- You will get
-- > 200
-- hello nodemcu

-- HTTPS DELETE Example with NULL header and body
http.delete("https://10.0.0.2:443","","",
function(code, data)
print(code)
print(data)
end)

-- HTTPS PUT Example with NULL header and body
http.put("https://testput.somewhere/somewhereyouput.php","","",
function(code, data)
print(code)
print(data)
end)

-- HTTP RAW Request Example, use more HTTP/HTTPS request method
http.request("http://www.apple.com:80/library/test/success.html","GET","","",
function(code, data)
print(code)
print(data)
end)
第2个回答  2015-12-12
ESP8266 RXD - 单片机 TXD,
ESP8266 TXD - 单片机 RXD,
具体需要 看模块 和 单片机 的 引脚排列,可以看 相关数据手册。
不同型号 排列 会有所不同。本回答被网友采纳