NodeMCU无法连接到网站

时间:2019-08-09 11:05:11

标签: http lua esp8266 nodemcu

我正在尝试通过以下代码将NodeMCU V3(基于ESP8266)连接到http://ya.ru

station_cfg={}
station_cfg.ssid="ssid" -- actual ssid was here
station_cfg.pwd="password" -- and password
server_link = "http://ya.ru"

wifi.setmode(wifi.STATION)
wifi.sta.config(station_cfg)
wifi.sta.connect()

http.put(server_link,
  'hi',
  function(code, data)
    print(code)
    if (code < 0) then
      print("HTTP request failed")
    else
      print(code, data)
    end
  end)

但是连接不成功,输出为:

HTTP client: Response too long (8461)

有什么问题? SSID和密码正确。所有GETPOSTPUT方法都存在相同的问题。

UPD: 嗯,所有这些都可以在Arduino IDE中用C语言编写的相同脚本正常工作。无论如何,对于Lua解释器无法执行此类请求,但从C编译的版本可以执行这样的请求,我感到很奇怪。

1 个答案:

答案 0 :(得分:0)

  

有什么问题吗?

HTTP模块实际上非常准确地告诉您出了什么问题。

HTTP client: Response too long (8461)

响应太长。在这种情况下,太长意味着:超出其处理能力。看来您需要根据https://nodemcu.readthedocs.io/en/latest/modules/net/#netsocketsend

使用低级net:socket:send()
相关问题