ESP32 v2 + SD Card + appendfile von mehreren Werten und Datum

Servus Maker,

darf ich Euch um Hilfe bitten. Bin mehr Lego-Bauer als Coder, das ist wohl einer der Hauptgründe :slight_smile: .
Leider schaffe ich es seit Freitag nicht, einen ESP32-V2-Code zu erstellen, der Werte auf eine SD-Card schreibt. SD-Card und ESP32 ist etwas anders als bei Arduino. Hardwaremäßig ist alles bereits fertig, der Beispielsketch schreibt auf die SD.

Compiler meckert ständig, wobei ich glaube, SIE liegt falsch...aber erklär ihr das mal...:o

Ziel ist es, Sensorwerte (float und int) und Datum(char) für einen Bienenstock für spätere Auswertungen in die nächste Zeile einer MicroSD zu schreiben (1xje Stunde). Die nachstehende Anleitung hat mir leider nicht weit genug geholfen.
https://forum.arduino.cc/index.php?topic=621038.0

Hier der Code (Fehler hier: invalid use of non-lvalue array // ist nur ein Auszug der Fehler, hab viele Varianten versucht...)

#include "FS.h"
#include "SD.h"
#include "SPI.h"


int Gesamtgewicht = 15000; //Beispielwerte
int Temp = 25;
int LF = 60;
int Press = 1000;
float vin = 12.5;



void appendFile(fs::FS &fs, const char * path, const char * message){
    Serial.printf("Appending to file: %s\n", path);

    File file = fs.open(path, FILE_APPEND);
    if(!file){
        Serial.println("Failed to open file for appending");
        return;
    }
    if(file.print(message)){
        Serial.println("Message appended");
    } else {
        Serial.println("Append failed");
    }
    file.close();
}



void setup()
{


}

void loop(){

String strGesamtgewicht = Gesamtgewicht;
String strTemp = Temp;
String strLF = LF;
String strPress = Press;
String strvin = vin;
String strdatum = "Datum";
String werte;

werte = strdatum+= strGesamtgewicht += ";" += strTemp += ";" += strLF += ";" += strPress += ";" += strvin += "\r\n";

appendFile(SD, "/hello.txt", werte.c_str());

delay(10000);
}

Bitte um einen einfachen Code, damit ich die Antworten verstehe und besser dazulerne :slight_smile:

Grüße, Danke im Voraus,
Pucki

Dann gib uns doch mal die komplette Fehlermeldung (bitte in Codetags). Da steht die Zeile drin und wir müssen nicht suchen.

Gruß Tommy

Servus,

denke der K(n)ackpunkt ist bei

void appendFile(fs::FS &fs, const char * path, const char * message){
appendFile(SD, "/hello.txt", werte.c_str());

der Versuch hier const char zu erzeugen mit werte.c_str() klappt nicht...

Nachstehend die kopierte Fehlermeldung.

Grüße, Danke im Voraus,
Pucki

Arduino: 1.8.12 (Windows 10), Board: "ESP32 Dev Module, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 115200, None"

H:\03_ESP32\01_Hardwarecode\05_SD\SD_Test_ESP32_2\SD_Test_ESP32_2.ino: In function 'void loop()':

SD_Test_ESP32_2:40:29: error: conversion from 'int' to 'String' is ambiguous

   String strGesamtgewicht = Gesamtgewicht;

                             ^

In file included from C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/Arduino.h:146:0,

                 from sketch\SD_Test_ESP32_2.ino.cpp:1:

C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/WString.h:59:9: note: candidate: String::String(const __FlashStringHelper*) <near match>

         String(const __FlashStringHelper *str);

         ^

C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/WString.h:59:9: note:   conversion of argument 1 would be ill-formed:

SD_Test_ESP32_2:40:29: error: invalid conversion from 'int' to 'const __FlashStringHelper*' [-fpermissive]

   String strGesamtgewicht = Gesamtgewicht;

                             ^

In file included from C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/Arduino.h:146:0,

                 from sketch\SD_Test_ESP32_2.ino.cpp:1:

C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/WString.h:57:9: note: candidate: String::String(const char*) <near match>

         String(const char *cstr = "");

         ^

C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/WString.h:57:9: note:   conversion of argument 1 would be ill-formed:

SD_Test_ESP32_2:40:29: error: invalid conversion from 'int' to 'const char*' [-fpermissive]

   String strGesamtgewicht = Gesamtgewicht;

                             ^

SD_Test_ESP32_2:41:20: error: conversion from 'int' to 'String' is ambiguous

   String strTemp = Temp;

                    ^

In file included from C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/Arduino.h:146:0,

                 from sketch\SD_Test_ESP32_2.ino.cpp:1:

C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/WString.h:59:9: note: candidate: String::String(const __FlashStringHelper*) <near match>

         String(const __FlashStringHelper *str);

         ^

C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/WString.h:59:9: note:   conversion of argument 1 would be ill-formed:

SD_Test_ESP32_2:41:20: error: invalid conversion from 'int' to 'const __FlashStringHelper*' [-fpermissive]

   String strTemp = Temp;

                    ^

In file included from C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/Arduino.h:146:0,

                 from sketch\SD_Test_ESP32_2.ino.cpp:1:

C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/WString.h:57:9: note: candidate: String::String(const char*) <near match>

         String(const char *cstr = "");

         ^

C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/WString.h:57:9: note:   conversion of argument 1 would be ill-formed:

SD_Test_ESP32_2:41:20: error: invalid conversion from 'int' to 'const char*' [-fpermissive]

   String strTemp = Temp;

                    ^

SD_Test_ESP32_2:42:18: error: conversion from 'int' to 'String' is ambiguous

   String strLF = LF;

                  ^

In file included from C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/Arduino.h:146:0,

                 from sketch\SD_Test_ESP32_2.ino.cpp:1:

C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/WString.h:59:9: note: candidate: String::String(const __FlashStringHelper*) <near match>

         String(const __FlashStringHelper *str);

         ^

C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/WString.h:59:9: note:   conversion of argument 1 would be ill-formed:

SD_Test_ESP32_2:42:18: error: invalid conversion from 'int' to 'const __FlashStringHelper*' [-fpermissive]

   String strLF = LF;

                  ^

In file included from C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/Arduino.h:146:0,

                 from sketch\SD_Test_ESP32_2.ino.cpp:1:

C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/WString.h:57:9: note: candidate: String::String(const char*) <near match>

         String(const char *cstr = "");

         ^

C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/WString.h:57:9: note:   conversion of argument 1 would be ill-formed:

SD_Test_ESP32_2:42:18: error: invalid conversion from 'int' to 'const char*' [-fpermissive]

   String strLF = LF;

                  ^

SD_Test_ESP32_2:43:21: error: conversion from 'int' to 'String' is ambiguous

   String strPress = Press;

                     ^

In file included from C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/Arduino.h:146:0,

                 from sketch\SD_Test_ESP32_2.ino.cpp:1:

C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/WString.h:59:9: note: candidate: String::String(const __FlashStringHelper*) <near match>

         String(const __FlashStringHelper *str);

         ^

C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/WString.h:59:9: note:   conversion of argument 1 would be ill-formed:

SD_Test_ESP32_2:43:21: error: invalid conversion from 'int' to 'const __FlashStringHelper*' [-fpermissive]

   String strPress = Press;

                     ^

In file included from C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/Arduino.h:146:0,

                 from sketch\SD_Test_ESP32_2.ino.cpp:1:

C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/WString.h:57:9: note: candidate: String::String(const char*) <near match>

         String(const char *cstr = "");

         ^

C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/WString.h:57:9: note:   conversion of argument 1 would be ill-formed:

SD_Test_ESP32_2:43:21: error: invalid conversion from 'int' to 'const char*' [-fpermissive]

   String strPress = Press;

                     ^

SD_Test_ESP32_2:44:19: error: conversion from 'float' to non-scalar type 'String' requested

   String strvin = vin;

                   ^

SD_Test_ESP32_2:48:100: error: no match for 'operator+=' (operand types are 'const char [2]' and 'String')

   werte = strdatum += strGesamtgewicht += ";" += strTemp += ";" += strLF += ";" += strPress += ";" += strvin += "\r\n";

                                                                                                    ^

Mehrere Bibliotheken wurden für "SD.h" gefunden
 Benutzt: C:\Users\MARS\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\SD
 Nicht benutzt: C:\Program Files (x86)\Arduino\libraries\SD
exit status 1
conversion from 'int' to 'String' is ambiguous

Dieser Bericht wäre detaillierter, wenn die Option
"Ausführliche Ausgabe während der Kompilierung"
in Datei -> Voreinstellungen aktiviert wäre.
1 Like

LÖSUNG!

Servus,

hab am Vormittag einen Kumpel getroffen der Programmierer ist. Der hat das schnell erledigt... :o

#include "FS.h"
#include "SD.h"
#include "SPI.h"


int Gesamtgewicht = 15000; //Beispielwerte
int Temp = 25;
int LF = 60;
int Press = 1000;




void appendFile(fs::FS &fs, const char * path, const char * message) {
  Serial.printf("Appending to file: %s\n", path);

  File file = fs.open(path, FILE_APPEND);
  if (!file) {
    Serial.println("Failed to open file for appending");
    return;
  }
  if (file.print(message)) {
    Serial.println("Message appended");
  } else {
    Serial.println("Append failed");
  }
  file.close();
}



void setup()
{
Serial.begin(115200);
 if(!SD.begin()){
        Serial.println("Card Mount Failed");
        return;
    }
}

void loop() {
  String werte = String(Gesamtgewicht) + ";" + String(Temp) + ";" + String(LF) + "\r\n";

 //String datum = String(now.day()) + "." + 

  appendFile(SD, "/DATEN.txt", werte.c_str());

  delay(5000);
}

Danke nochmals für Eure Zeit. Hoffe anderen ist mit dem Code auch geholfen!

Grüße,
Pucki

1 Like