I'm using a firmware made using http://nodemcu-build.com/. Options - net, http, crypt, ...
I'm trying to make an HTTPS POST request needed to feed data in a platform. The following code works when using HTTP but blocks without any message for HTTPS.
I'm not so familiar with HTTPs so any advice is welcomed !
-- Test host and url
host='httpbin.org'
url='/post'
port=443 --80
-- Test values to be replaced by real sensor data
temp=123
light=426
ozone=123
po_string='[{"temp":'..temp..'},{"ozone":'..ozone..'},{"light":'..light..'426}]'
post_length=string.len(po_string)
trans="POST "..url.." HTTP/1.1\r\nHost: "..host.."\r\n"
.."Connection: keep-alive\r\n"
.."Content-Type: application/json"
.."\r\nAccept: */*\r\nContent-length: "..post_length.."\r\n\r\n"
..po_string
print(trans)
conn=net.createConnection(net.TCP, 1) -- 0
conn:on("receive", function(cnn, payload)
print(payload)
end )
conn:on("sent",function(cnn)
print("Sent !")
end)
conn:on("connection",function(cnn)
print("Connected")
cnn:send(trans)
end)
conn:connect(port,host)