Hello,
im using a ESP32. I already wrote code for saving strings to a SD card (It works perfectly and saves everything). I use the SD libary.
Now i get a pointer to the array which has all the values i want to save.
The header String gets saved to the SD card no problem, but the actual datastring doesnt get saved. Both are Strings, both use the same function to save, but the header saves onto the SD card and the datastring doesnt.
To clarify this. When i open the .csv file i just see "ID; Value". So no data gets saved but only the header
This is kind of a big project so i will just post the function, the setup and the class.
I thank you in advance for helping me with my problem ![]()
Another question to this post:
Could i change the file name while the program is running? Like have data1.csv, data2.csv, data3.csv and so on
void setup() {
Serial.begin(115200);
p_EKG_state_1 = &EKG_state_1;
pinMode(CS_Pin, OUTPUT);
if(!SD.begin(CS_Pin))
{
Serial.println("Card failed or not present");
}
EKG_data_transmision.matrixData = SD.open("/data.csv", FILE_APPEND); //erstelle data.csv datei
if(EKG_data_transmision.matrixData)
{
String header = "ID; Value;";
EKG_data_transmision.matrixData.println(header);
EKG_data_transmision.matrixData.close();
Serial.println(header);
Serial.println("card init sucess");
}
else
{
Serial.println("Couldnt open vector data file");
}
}
Here is the function where everything should go down.
bool EKG_data_transmision::write_matrix_to_SD(unsigned short *array_pointer)
{
if(!SD.begin(CS_Pin))
{
Serial.println("Card failed or not present");
return 1;
}
matrixData = SD.open("/data.csv", FILE_APPEND); //erstelle data.csv datei
if(matrixData)
{
//sd karte immer noch da und schau ob data.csv exisitiert
while(matrix_coloum < 3070)
{
if(matrix_coloum == 1024 || matrix_coloum == 2048)
{
header = "ID; Value;\n";
matrixData.println(header);
}
dataString = String(matrix_coloum) + "; " + "\n"; // + String(*array_pointer)
matrixData.println(dataString);
//Serial.println("This is datastring:");
Serial.println(dataString);
array_pointer++;
matrix_coloum++;
}
}
else{
Serial.println("Error writing to file !");
}
matrixData.close(); // close the file
return 0;
}
Here is the class
#include "Arduino.h"
#include <WiFi.h>
#include "SD.h"
#include "SPI.h"
#include <vector>
#include <string>
class EKG_data_transmision
{
private:
String dataString;
String header;
unsigned short matrix_coloum = 0;
public:
EKG_data_transmision();
File matrixData;
//Def Funktions:
bool write_matrix_to_SD(unsigned short *array_pointer);
bool delete_matrix_from_SD(unsigned int record);
bool send_record_to_DB(unsigned int record);
bool connect_wifi(char* ssid, char *password);
unsigned int count_record_from_SD();
unsigned int get_last_record_from_SD();
void set_sendingprogress(unsigned int record);
unsigned int get_sendingprogress(unsigned int record);
void set_wifi_password(char* password);
char* get_wifi_password();
void set_wifi_ssid(char* ssid);
char* get_wifi_ssid();
};