ciao a tutti
vorrei scaricare un bollettino meteo da l sito aviation weather, in pratica, inviando dal browser questa richiesta http://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=csv&stationString=LIML&hoursBeforeNow=1 ti inviano il metar (bollettino meteo aeronautico) più recente in formato .csv.
La pagina che illustra il servizio è questa AWC - ADDS Text Data Server
Sto adoperando un wemos D1 mini con ide Arduino che poi invierà i dati ad un Arduino duemilanove.
Il problema è che ... non riesco. Ho provato diverse soluzioni ma nessuna ha funzionato, gli errori riportati vanno da 400 "bad request" a 301 " file temporary moved" a richiesta fuori tempo massimo ecc.
Il codice è il seguente:
void loop() {
if (client.connect("aviationweather.gov/adds/dataserver_current", 80)) {
Serial.println("connesso al server");
client.println("GET http://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=csv&stationString=LIML&hoursBeforeNow=1 HTTP/1.1");
client.println("Host:aviationweather.gov/adds/dataserver_current");
client.println();
delay(1000);
while(client.connected() && !client.available()) delay(1);
while (client.available()) {
int c = client.read();
String line = client.readStringUntil('\r');
Serial.print("client read: "); Serial.println(c);
Serial.print("stringa: "); Serial.println(line);
}
client.stop();
client.flush();
}
delay(10000);
}
Nella intestazione c'è i'inizializzazione del client "WiFiClient client" e in void setup() c'è la inizializzazione della seriale e la connessione al wifi.
Questa è la risposta sul monitor seriale:
connesso al server
client read: 72
stringa: TTP/1.1 400 Bad Request
client read: 10
stringa: Server: nginx
client read: 10
stringa: Date: Fri, 11 Jan 2019 09:55:54 GMT
client read: 10
stringa: Content-Type: text/html
client read: 10
stringa: Content-Length: 166
client read: 10
stringa:
client read: 10
stringa: <html>
client read: 10
stringa: <head><title>400 Bad Request</title></head>
client read: 10
stringa: <body bgcolor="white">
client read: 10
stringa: <center><h1>400 Bad Request</h1></center>
client read: 10
stringa: <hr><center>nginx</center>
client read: 10
stringa: </body>
client read: 10
stringa: </html>
Dove sbaglio?
Grazie in anticipo.