11.07.2022, 06:28
You have an old firmware which does not support HTTPS directly in socket.http. ssl.https must be used instead.
The request part can be rewritten like this to work with older firmware:
The request part can be rewritten like this to work with older firmware:
Code:
latitude = 40.4538899
longitude = -3.6211718
https = require('ssl.https')
json = require('json')
ltn12 = require('ltn12')
args = 'lat=' .. latitude .. '&lon=' .. longitude
url = 'https://api.met.no/weatherapi/locationforecast/2.0/compact?' .. args
mac = 0
io.readfile('/sys/class/net/eth0/address'):gsub('%x%x', function(v)
mac = mac * 256 + tonumber(v, 16)
end)
response = {}
res, code = https.request({
url = url,
protocol = 'tlsv12',
headers = {
['user-agent'] = 'LM ' .. mac
},
sink = ltn12.sink.table(response)
})
if res and code == 200 then
data = json.pdecode(table.concat(response))
end
if type(data) == 'table' then
log(data)
else
log('request failed', res, code)
end