String verarbeiten aus HTTP abruf

Hallo zusammen,
ich habe bei mir den Volkszähler installiert und möchte nun die Bezugsleistung weiter verarbeiten.
Dazu benötige ich diese jedoch als "Zahl".
Aktuell hab ich das Problem, dass ich diese nur als String im Format z.B. "123.45678 W" oder "0 W" bekomme.

ich schaffe es nicht die reine Zahl aus dem String "aktLeistung" zu extrahieren, damit ich damit am Ende weiter rechnen kann.

Ich benutze einen ESP8266
Hier ist der aktuelle Code

// put your setup code here, to run once:
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>

const char* ssid = "***";
const char* password = "***";

void setup () {
    pinMode(LED_BUILTIN, OUTPUT);

  Serial.begin(115200);
  delay(1000);

  Serial.print("Connect to Wifi ");

  IPAddress ip(192, 168, 178, 101);
  IPAddress dns(192, 168, 178, 1);
  IPAddress gateway(192, 168, 178, 1);
  IPAddress subnet(255, 255, 255, 0);
  WiFi.config(ip, dns, gateway, subnet);

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print (".");
  }

  Serial.println("");
  Serial.println("Wifi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  }
  
void loop(){
if (WiFi.status() == WL_CONNECTED) 
{

    WiFiClient client;

    HTTPClient http;

    if (http.begin(client, "http://192.168.178.100/data/c32459a0-f6ba-11ea-8a62-035d072e1a34.txt?from=now")) {  // HTTP

      int httpCode = http.GET();            // start connection and send HTTP header

      if (httpCode > 0) {                   // httpCode will be negative on error
                                            // HTTP header has been send and Server response header has been handled
        
        if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {  // file found at server
          String aktLeistung = http.getString();
          Serial.print("aktuelle Bezugsleistung ist: ");
          Serial.println(aktLeistung);

        }
      } else {
        Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
      }

      http.end();
    } else {
      Serial.printf("[HTTP} Unable to connect\n");
    }
  }

  delay(5000);
}

und das ist meine aktuelle Ausgabe:

...
Wifi connected
IP address:
192.168.178.101
aktuelle Bezugsleistung ist: 0 W
aktuelle Bezugsleistung ist: 0 W
aktuelle Bezugsleistung ist: 0 W
aktuelle Bezugsleistung ist: 0 W
aktuelle Bezugsleistung ist: 0 W

0W da die Sonne scheint und die PV einspeist

Vielen Dank schonmal vorab

Du suchst die Arduino-Referenz von String.

Gruß Tommy

Hallo

schau dir mal die Referenz an

und da String.toInt() oder String.toFloat()

Tommy56 war schneller :slight_smile:

Heinz