HTTPS (SSL) get request with NodeMCU

非 Y 不嫁゛ 提交于 2019-12-01 08:07:45

问题


I would like to perform GET requests to googleapi.com with my ESP8266 running NodeMCU, to get some data from the google Calendar API. The website allows only secured connection (HTTPS/SSL).

First, I've been trying to connect to google.com (secured) to give it a try, but with no success either. Here is the LUA code:

conn=net.createConnection(net.TCP, 1)
conn:on("receive", function(sck, c) print(c) end )
conn:on("connection", function(conn)
      print("connected")
      conn:send("HEAD / HTTP/1.1\r\n".. 
             "Host: google.com\r\n"..
             "Accept: */*\r\n"..
             "User-Agent: Mozilla/4.0 (compatible; esp8266 Lua;)"..
             "\r\n\r\n") 
end )
conn:on("disconnection", function(conn)  print("disconnected") end )
conn:connect(443,"google.com")

Nothing is triggered (not even the "connected").

I also downloaded the latest version of nodemcu (master branch) from the website http://nodemcu-build.com by selecting the SSL support.

NodeMCU custom build by frightanic.com
    branch: master
    commit: c8037568571edb5c568c2f8231e4f8ce0683b883
    SSL: true

Could someone tell me what I am doing wrong? Someone reported the problem on Reddit, but no final solution given.


回答1:


The required fix for the net module is not yet available on the master branch. PR 1014 was only merged to the dev branch in early February.

The dev branch has an HTTP client module with which your code can be shortened to a one-liner. See http://nodemcu.readthedocs.org/en/dev/en/modules/http/#httpget for details.



来源:https://stackoverflow.com/questions/35988328/https-ssl-get-request-with-nodemcu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!