09.07.2022, 23:16
Hello,
Please, I hope you could help me in my issue
However, Until now i had script work fine , but now i cant obtain weather dates,
This is the scheduled script that I used.
I can see on log :
* arg: 1
* string: <html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
<hr><center>nginx/1.18.0 (Ubuntu)</center>
</body>
</html>
Please, I hope you could help me in my issue
However, Until now i had script work fine , but now i cant obtain weather dates,
This is the scheduled script that I used.
I can see on log :
* arg: 1
* string: <html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
<hr><center>nginx/1.18.0 (Ubuntu)</center>
</body>
</html>
Code:
latitude = 40.4538899
longitude = -3.6211718
json = require('json')
http2 = require('socket.http')
log (http2)
--http = require('ssl.https')
--log ( http)
args = 'lat=' .. latitude .. '&lon=' .. longitude
url = 'https://api.met.no/weatherapi/locationforecast/2.0/compact?' .. args
--url = 'https://api.met.no/weatherapi/locationforecast/2.0/complete?' .. args
mac = 0
io.readfile('/sys/class/net/eth0/address'):gsub('%x%x', function(v)
mac = mac * 256 + tonumber(v, 16)
end)
http2.USERAGENT = 'LM ' .. mac
res, err = http2.request(url)
log ( res, err)
data = json.pdecode(res)
log (data)
if type(data) == 'table' then
date = os.date('*t')
date.day = date.day + 1
time = os.time(date)
timestamp = os.date('%Y-%m-%d', time)
log(data)