HTTP客户端:出现错误:-114 Lua

我正在尝试使用我的nodemcu与Thingspeak通信。我正在使用lua并尝试使用GET请求推送数据,但我得到(几乎是...)错误:

> HTTP客户端:连接错误:-114
HTTP客户端:连接超时
HTTP请求失败

我不知道为什么。我已经连接到我的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请求失败”)
    else
      print(code,data)
    end
  end)

这是我的模块:

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

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

点赞
用户4347173
用户4347173

我使用 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)
2021-11-28 14:12:04