Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Having issue to read the SPIFF file. #14

Closed
@OttoKlaasen

Description

@OttoKlaasen

Dear Sir,
following code does not seem to work:

// we could open the file
size_t size = f.size();
// Allocate a buffer to store contents of the file.
std::unique_ptr<char[]> buf(new char[size]);
// Read and store file contents in buf
f.readBytes(buf.get(), size);

I get rubish in buf, i had to rewrite like this to be able to read by SPIFF file:

File f = SPIFFS.open(CONFIG_FILE, "r");
String buffer; /// Create a string buffer to get the file contents
//
Serial.println("Get file");
if (!f) Serial.println("FAIL TO LOAD FILE");
while (f.available()){
buffer = f.readString().c_str();
}
Serial.print("file buffer: ");Serial.println(String(buffer)); // Print buffer which contains file contents

char * doc = new char [buffer.length()+1]; // Define a pointer to a char buffer called doc
std::strcpy (doc, buffer.c_str()); // Copy string buffer to char buffer caled doc

Serial.print("doc: ");Serial.println(String(doc)); // Print doc as string
// Do the joson stuff
StaticJsonDocument<1024> json;
Serial.println("deserialize !");

of course add this in a header file:
// strings and c-strings
#include
#include
#include

Cheers and greetings from the netherland.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions