I am trying to send data to cloud using secure websocket (wss). The cloud interface only allows secure websocket ( HTTP, non-secure websocket etc are not allowed)
I tried the latest master,dev builds from nodemcu-build.com , but there SSL is failing. Even HTTPs is not working. So I tried the "1.5.4.1-final" build. Here I verified SSL is working for HTTPS:
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")
> connected
HTTP/1.1 302 Found
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Referrer-Policy: no-referrer
Location: https://www.google.co.in/?gfe_rd=cr&ei=HWhHWffUGojT8ge-wrS4Cw
Content-Length: 262
Date: Mon, 19 Jun 2017 05:58:53 GMT
Alt-Svc: quic=":443"; ma=2592000; v="38,37,36,35"
But when I tried both non-secure websocket and secure websocket, only non-secure websocket worked. This is the log for successful non-secure connection:
ws = websocket.createClient()
> ws:on("connection", function()
print('connection opened', status)
end)
> ws:on("receive", function(_, msg, opcode)
print('got message:', msg, opcode) -- opcode is 1 for text message, 2 for binary
end)
> ws:on("close", function(_, status)
print('connection closed', status)
ws = nil -- required to lua gc the websocket client
end)
> ws:connect('ws://echo.websocket.org/')
> connection opened nil
And this is for failed secure connection:
> ws = websocket.createClient()
> ws:on("connection", function()
>> print('connection opened', status)
end)
> ws:on("receive", function(_, msg, opcode)
print('got message:', msg, opcode) -- opcode is 1 for text message, 2 for binary
end)
> ws:on("close", function(_, status)
>> print('connection closed', status)
ws = nil -- required to lua gc the websocket client
end)
> ws:connect('wss://echo.websocket.org/')
> connection closed -128
Is secure websocket not supported in nodemcu ? If not, how can I get secure websocket working? Is there any extra code required for secure websocket compared non-secure?