【问题标题】:HTTP client: Disconnected with error: -114 LuaHTTP 客户端:因错误断开连接:-114 Lua
【发布时间】:2021-05-11 14:18:42
【问题描述】:

我正在尝试使用我的 nodemcu 与 thingspeak 进行通信。我正在使用 lua,我正在尝试使用 get 请求推送数据,但我得到(字面意思...)这个错误:

> HTTP client: Disconnected with error: -114
HTTP client: Connection timeout
HTTP request failed

我不知道为什么。我已连接到我的 wifi,这是我的代码:

url = "https://api.thingspeak.com/update.json?api_key=XXXXXXXXXXXXXXXXX&field1=" .. temp
print(url)
http.get(url, nil, function(code, data)
    if (code < 0) then
      print("HTTP request failed")
    else
      print(code, data)
    end
  end)

这是我的模块:

crypto,dht,file,gpio,http,mdns,mqtt,net,node,pwm,sjson,spi,tmr,tsl2561,uart,websocket,wifi,tls

有什么想法吗?我不知道该怎么办。

【问题讨论】:

  • 这可能是因为您使用的是加密的 HTTP 连接。我建议您阅读 nodemcu.readthedocs.io/en/latest/modules/http 和 TLS 模块文档的限制。
  • 我读了这篇文章,你认为这是因为 thingspeak 的证书链太大而我的内存不足吗?在这种情况下,我避免该问题的想法很好,因为我在 lan 中使用 http protocolo 与树莓零 w 作为集线器进行通信。而不是关于 mqtt 为什么我收到错误“未授权”?如果我尝试将 mqtt 与我的 android 应用程序或我的 python 脚本一起使用,它工作得很好。也许是因为它甚至在 mqtt 中也使用 ssl/tls?所以也许无论如何都会出现同样的问题

标签: http https lua esp8266 nodemcu


【解决方案1】:

我使用“http.post”将我的传感器读数上传到 ThingSpeak:

  http.post('http://api.thingspeak.com/update',
     'Content-Type: application/json\r\n',
     '{"api_key":"'..tsapikey..'","field1":"'..field1..'","field2":"'..field2..'","field3":"'..field3..'","field4":"'..field4..'"}',
     function(code, data)
        if (code < 0) then
           print("HTTP request failed")
        else
           print(code, data)
        end
     end)

【讨论】:

    猜你喜欢
    • 2012-05-31
    • 2022-01-12
    • 2017-09-29
    • 1970-01-01
    • 2010-11-01
    • 2017-07-17
    • 2021-12-05
    相关资源
    最近更新 更多