You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 4, 2023. It is now read-only.
// 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.
The text was updated successfully, but these errors were encountered:
Hello,
Thanks for using the library and finding out the bug/mistake.
The issue is that the buffer is not allocated large enough, lacking one NULL terminating byte.
Please change the corresponding code of these affected examples
size_t configFileSize = configFile.size();
Serial.println(configFileSize);
// Allocate a buffer to store contents of the file.
std::unique_ptr<char[]> buf(newchar[configFileSize + 1]);
Your solution is working OK and you can keep using it.
Those examples will be uploaded to the Master, and included in the next Release.
Fix [Having issue to read the SPIFF file](#14) for
1. [ConfigOnSwitchFS](examples/ConfigOnSwitchFS)
2. [ConfigPortalParamsOnSwitch](examples/ConfigPortalParamsOnSwitch)
### Releases 1.0.7
1. Use `just-in-time` scanWiFiNetworks() to reduce connection time necessary for battery-operated DeepSleep application. Thanks to [CrispinP](https://github.com/CrispinP) for identifying, requesting and testing. See [Starting WiFIManger is very slow (2000ms)](#6)
2. Fix bug relating SPIFFS in examples :
- [ConfigOnSwitchFS](examples/ConfigOnSwitchFS)
- [ConfigPortalParamsOnSwitch](examples/ConfigPortalParamsOnSwitch) (now support ArduinoJson 6.0.0+ as well as 5.13.5-)
- [AutoConnectWithFSParameters](examples/AutoConnectWithFSParameters)
See [Having issue to read the SPIFF file](#14), Thanks to [OttoKlaasen](https://github.com/OttoKlaasen) to report.
3. Fix [README](README.md). See [Accessing manager after connection](#15)
Dear Sir,
following code does not seem to work:
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.
The text was updated successfully, but these errors were encountered: