2

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.

S. Blanc
  • 107
  • 2
  • 9

1 Answers1

2

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.

Marcel Stör
  • 22,695
  • 19
  • 92
  • 198
  • Thank you for this answer. Indeed the `http.get()` function works perfectly. – S. Blanc Mar 16 '16 at 15:36
  • The HTTP solution works for me too. Is there any update on using the NodeMCU Net Module? I feel that establishing a connection and making requests will allow the chip to make more ssl requests faster than renegotiating the connection via the http.post command. – Joe Andolina Apr 21 '16 at 04:13
  • @JoeAndolina you may follow https://github.com/nodemcu/nodemcu-firmware/issues/1146 – Marcel Stör Apr 21 '16 at 04:57