Lesen bis zum ersten Zeilenvorschub, Inhalt wegwerfen, dann lesen bis zum nächsten Zeilenvorschub, diesen durch '\0' ersetzen - Verarbeiten.
Also genau so, als würdest Du von der seriellen Schnittstelle einlesen. Dazu gibt es hier im Forum viele Beispiele.
Wenn nur noch Feintuning zu tun ist, dann zeige doch mal, was Du schon hast. Da kann man darauf aufbauen.
/*
Rui Santos
Complete project details at Complete project details at https://RandomNerdTutorials.com/esp32-http-get-post-arduino/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "SSID";
const char* password = "PASSWORD";
//Your Domain name with URL path or IP address with path
String serverName = "https://tgftp.nws.noaa.gov/data/observations/metar/stations/";
// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastTime = 0;
// Timer set to 10 minutes (600000)
//unsigned long timerDelay = 600000;
// Set timer to 10 seconds
unsigned long timerDelay = 10000;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
Serial.println("Timer set to 5 seconds (timerDelay variable), it will take 5 seconds before publishing the first reading.");
}
void loop() {
//Send an HTTP POST request every 10 minutes
if ((millis() - lastTime) > timerDelay) {
//Check WiFi connection status
if(WiFi.status()== WL_CONNECTED){
HTTPClient http;
String serverPath = serverName + "EDDM.TXT";
// Your Domain name with URL path or IP address with path
http.begin(serverPath.c_str());
// Send HTTP GET request
int httpResponseCode = http.GET();
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println(payload);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
}
else {
Serial.println("WiFi Disconnected");
}
lastTime = millis();
}
}
Das Auseinanderpflücken des Strings payload bekommst Du selbst hin.
Der beisppielcode funktioniert bei mir nicht. Ich habe ein ESP8266 und da
will " <HTTPClient.h>" nicht kompiliert werden. Jetzt habe ich es mit der "ESP8266HTTPClient.h" versucht.
Leider bekomme ich beim "httpResponseCode" eine "-1".
Mit dem WLAN bin ich verbunden und bekomme auch eine IP.
Hier mein Funktion:
void getMetar(){
HTTPClient http;
// Your Domain name with URL path or IP address with path
http.begin(serverPath);
Serial.print(serverPath);
// Send HTTP GET request
int httpResponseCode = http.GET();
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println(payload);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
}
Würde mich über eine weitere Idee von euch freuen.
Wenn das Flugwetter zu realen Flügen beitragen sollte, dürfte dieser Unsicherheitsfaktor nicht zulässig sein.
Da sollte man die Identität des Servers checken.
@Tommy56
Das stimmt natürlich, ich bin da für reale Fliegerei bei Dir (ob da ein ESP8266 mitfliegen sollte, ist nochmal eine andere Frage).
Danke für den expliziten Hinweis!
Es geht hier nicht um die reale Fliegerei. Es geht hier um den MSFS2020.
/*
Rui Santos
Complete project details at Complete project details at https://RandomNerdTutorials.com/esp8266-nodemcu-http-get-post-arduino/
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
Code compatible with ESP8266 Boards Version 3.0.0 or above
(see in Tools > Boards > Boards Manager > ESP8266)
*/
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecure.h>
const char* ssid = "xxxx"; // SSID of local network
const char* password = "xxxx"; // Password on network
//Your Domain name with URL path or IP address with path
String serverName = "https://tgftp.nws.noaa.gov/data/observations/metar/stations/";
String serverPath = serverName + "EDDM.TXT";
// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastTime = 0;
// Timer set to 10 minutes (600000)
//unsigned long timerDelay = 600000;
// Set timer to 5 seconds (5000)
unsigned long timerDelay = 5000;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
Serial.println("Timer set to 5 seconds (timerDelay variable), it will take 5 seconds before publishing the first reading.");
}
void loop() {
// Send an HTTP POST request depending on timerDelay
if ((millis() - lastTime) > timerDelay) {
//Check WiFi connection status
if(WiFi.status()== WL_CONNECTED){
WiFiClientSecure client;
HTTPClient http;
client.setInsecure();
// Your Domain name with URL path or IP address with path
http.begin(client, serverPath.c_str());
// Send HTTP GET request
int httpResponseCode = http.GET();
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println(payload);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
}
else {
Serial.println("WiFi Disconnected");
}
lastTime = millis();
}
}