Skip to content

Commit 4aa19d8

Browse files
committed
Clear null secrets as some text readers wont open binary
1 parent 2ac1767 commit 4aa19d8

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/provisioning/tinyusb/Wippersnapper_FS.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,13 @@ bool Wippersnapper_FS::configFileExists() {
238238
// Does secrets.json file exist?
239239
if (!wipperFatFs.exists("/secrets.json"))
240240
return false;
241+
File32 file = wipperFatFs.open("/secrets.json", FILE_READ);
242+
if (!file)
243+
return false;
244+
int firstChar = file.peek();
245+
file.close();
246+
if (firstChar <= 0 || firstChar == 255)
247+
return false;
241248
return true;
242249
}
243250

@@ -324,7 +331,7 @@ bool Wippersnapper_FS::createBootFile() {
324331
void Wippersnapper_FS::createSecretsFile() {
325332
// Open file for writing
326333
File32 secretsFile = wipperFatFs.open("/secrets.json", FILE_WRITE);
327-
334+
secretsFile.truncate(0);
328335
// Create a default secretsConfig structure
329336
secretsConfig secretsConfig;
330337
strcpy(secretsConfig.aio_user, "YOUR_IO_USERNAME_HERE");
@@ -339,7 +346,7 @@ void Wippersnapper_FS::createSecretsFile() {
339346
serializeJsonPretty(doc, secretsFile);
340347
secretsFile.flush();
341348
secretsFile.close();
342-
349+
343350
writeToBootOut(
344351
"ERROR: Please edit the secrets.json file. Then, reset your board.\n");
345352
#ifdef USE_DISPLAY

0 commit comments

Comments
 (0)