Left here for archival purposes.

User avatar
By Alkorin
#24540 I had some problems trying to connect to a SSL Socket with NodeMCU: the "disconnection" event was called immediately after connect:

Code: Select all> conn=net.createConnection(net.TCP, 1)
> conn:on("connection", function(conn, payload) print("C") end )
> conn:on("reconnection", function(conn, payload) print("R") end )
> conn:on("disconnection", function(conn, payload) print("D") end )
> conn:on("receive", function(conn, payload) print("r") print(payload) end )
> conn:on("sent", function(conn, payload) print("s") end )
> conn:connect(4243,"167.114.255.153")
> D


I did some tcpdump and see it was a SSL exchange error and decided to fix it.

I tried to rebuild with the latest SDK (1.2) and dev120 branch from nodemcu and obtained the same result.

After some digging, if I build myself libssl and build the firmware with it, it works !

Code: Select allnodemcu-firmware/app/ssl$ make
nodemcu-firmware/app/ssl$ mv .output/eagle/debug/lib/libssl.a ../../lib/libn
nodemcu-firmware$ make clean && make && make flash

Code: Select all> conn=net.createConnection(net.TCP, 1)
> conn:on("connection", function(conn, payload) print("C") end )
> conn:on("reconnection", function(conn, payload) print("R") end )
> conn:on("disconnection", function(conn, payload) print("D") end )
> conn:on("receive", function(conn, payload) print("r") print(payload) end )
> conn:on("sent", function(conn, payload) print("s") end )
> conn:connect(4243,"167.114.255.153")
> C
conn:send("auth foo\n")
> s
r
auth failed

D


What's the difference between the shipped libssl.a and the one built with sources ?
And second question, why is it shipped if we can build it from sources ? :)
User avatar
By Alkorin
#24584 And SSL eats too much RAM :s

I've 30.5kB of free heap at boot, 23.1kB after having uploaded my code (which is not finished...), but the mcu restart as soon as I call it

Code: Select all> wifi.sta.getap({ ssid = "foobar" }, 1, uploadStats)
> Done

 ets Jan  8 2013,rst cause:4, boot mode:(3,6)


Any idea of how many free heap do we need to do ssl sockets ? I just try to post a message of ~500bytes :/

Edit: with some debug
Code: Select allclient handshake start.
No heap available, failed to malloc 1040
Fatal exception (29):
User avatar
By ap.esp8266
#32462 Hello!

I'm testing the following NodeMCU firmware:

NodeMCU custom build by frightanic.com
branch: dev140
commit: 340ef8fc0ae00be1960acebe0276702dc7a00cb0
SSL: true
modules: node,file,gpio,wifi,net,pwm,i2c,spi,tmr,adc,uart,ow,bit,mqtt,cjson,crypto
build built on: 2015-10-26 19:36
powered by Lua 5.1.4 on SDK 1.4.0

After being connected to the Internet, I run the following commands:

local SMTP_SERVER = "smtp.gmail.com"
local SMTP_PORT = "465"
conn=net.createConnection(net.TCP, 0)
conn:on("reconnection", function(co, payload) print("Reconected") end )
conn:on("disconnection", function(co, payload) print("Disconected") end )
conn:on("receive", function(co, payload) print("receivede -> ") print(payload) end )
conn:on("sent", function(co, payload) print("sent -> ") end )
conn:connect(SMTP_PORT,SMTP_SERVER)
conn:dns(SMTP_SERVER,function(sck,ip) print("SMTP Server: "..ip) end)
conn:on("connection", function(co, payload)
print("Conected")
local IP_ADDRESS = wifi.sta.getip()
conn:send("HELO "..IP_ADDRESS.."\r\n")
end )

And I get the following results on the console:

SMTP Server: 64.233.184.109
Conected
sent ->
receivede ->

Disconected


Changing the third line of the command for:
conn=net.createConnection(net.TCP, 1)

I just get:
SMTP Server: 64.233.184.109

Apparently, using the secure connection (conn = net.createConnection (Net.Tcp, 1)) none of the events is detected.
How one can we deal with events in the case of secure connections?
Are we in the presence of a firmware bug in the SSL module?

Thanks in advance to those who answer these questions and help overcome the difficulty in connecting to the email service of Google.