使用 HTTPS 与 Nodemcu 断开连接

Disconnection using HTTPS with Nodemcu

我正在使用以下版本:

NodeMCU custom build by frightanic.com
.branch: master
.commit: c8ac5cfb912ff206b03dd7c60ffbb2dafb83fe5e
.SSL: true
.modules: file,gpio,http,i2c,net,node,spi,tmr,uart,wifi,tls
 build .built on: 2017-06-03 03:24
 powered by Lua 5.1.4 on SDK 2.1.0(116b762)

使用 http 模块我可以成功调用 get:

> http.get("http://httpbin.org/ip", nil, function(code, data)
if (code < 0) then
  print("HTTP request failed")
else
  print(code, data)
end
end)>> >> 
> 200   {
"origin": "61.69.19.186"
}

使用 https 进行等效调用会导致超时:

http.get("https://httpbin.org/ip", nil, function(code, data)
if (code < 0) then
  print("HTTP request failed")
else
  print(code, data)
end
end)>> >> 

控制台上显示以下消息:

HTTP client: Disconnected with error: 9
HTTP client: Connection timeout

大约一年前的几个其他类似问题讨论了 net 模块所需的修复以及调用 httpbin.org 所需的特定版本的 SSL 实现:

今天在 mbedTLS 的 TLS/SSL 支持下创建了构建。

而不是在评论中,我将其作为 "answer" 提供,以便之后可以关闭问题(帮助那些在此处观看 nodemcu 标签的人)。

这是在 https://github.com/nodemcu/nodemcu-firmware/issues/1707 上跟踪的一个已知问题。 Espressif SDK 升级 2.0 似乎在建立安全 HTTP 连接时出现问题。

我在使用 NodeMCU 的 ESP8266 上看到错误 -11:

HTTP client: Disconnected with error: -11
HTTP client: Connection timeout

在我的例子中,它有助于禁用我路由器的防火墙(或者具体来说,IP flood/ICMP 泛洪设置)(我的应用程序突然停止工作,大概是因为路由器固件升级)。如果您无法在您的路由器中禁用这些设置,您可以尝试在另一个网络中或使用另一个路由器测试该应用程序。

(我知道这不能直接回答问题(抱歉!)但可能会帮助其他人,他们也使用 http.get() 并像问题的作者一样收到错误代码 < 0。 )