@@ -269,44 +269,52 @@ void Wippersnapper_FS::eraseBootFile() {
269
269
bool Wippersnapper_FS::createBootFile () {
270
270
bool is_success = false ;
271
271
char sMAC [18 ] = {0 };
272
+ String newContent;
272
273
273
- File32 bootFile = wipperFatFs.open (" /wipper_boot_out.txt" , FILE_WRITE);
274
- if (bootFile) {
275
- bootFile.println (" Adafruit.io WipperSnapper" );
276
-
277
- bootFile.print (" Firmware Version: " );
278
- bootFile.println (WS_VERSION);
279
-
280
- bootFile.print (" Board ID: " );
281
- bootFile.println (BOARD_ID);
282
-
283
- sprintf (sMAC , " %02X:%02X:%02X:%02X:%02X:%02X" , WS._macAddr [0 ],
284
- WS._macAddr [1 ], WS._macAddr [2 ], WS._macAddr [3 ], WS._macAddr [4 ],
285
- WS._macAddr [5 ]);
286
- bootFile.print (" MAC Address: " );
287
- bootFile.println (sMAC );
274
+ // Generate new content
275
+ newContent += " Adafruit.io WipperSnapper\n " ;
276
+ newContent += " Firmware Version: " + String (WS_VERSION) + " \n " ;
277
+ newContent += " Board ID: " + String (BOARD_ID) + " \n " ;
278
+ sprintf (sMAC , " %02X:%02X:%02X:%02X:%02X:%02X" , WS._macAddr [0 ],
279
+ WS._macAddr [1 ], WS._macAddr [2 ], WS._macAddr [3 ], WS._macAddr [4 ],
280
+ WS._macAddr [5 ]);
281
+ newContent += " MAC Address: " + String (sMAC ) + " \n " ;
288
282
289
283
#if PRINT_DEPENDENCIES
290
- bootFile.println (" Build dependencies:" );
291
- bootFile.println (project_dependencies);
284
+ newContent += (" Build dependencies:\n " );
285
+ newContent += (project_dependencies);
286
+ newContent += (" \n " );
292
287
#endif
293
288
294
- // Print ESP-specific info to boot file
295
- #ifdef ARDUINO_ARCH_ESP32
296
- // Get version of ESP-IDF
297
- bootFile.print (" ESP-IDF Version: " );
298
- bootFile.println (ESP.getSdkVersion ());
299
- // Get version of this core
300
- bootFile.print (" ESP32 Core Version: " );
301
- bootFile.println (ESP.getCoreVersion ());
302
- #endif
289
+ #ifdef ARDUINO_ARCH_ESP32
290
+ newContent += " ESP-IDF Version: " + String (ESP.getSdkVersion ()) + " \n " ;
291
+ newContent += " ESP32 Core Version: " + String (ESP.getCoreVersion ()) + " \n " ;
292
+ #endif
293
+
294
+ // Check if the file exists and read its content
295
+ File32 bootFile = wipperFatFs.open (" /wipper_boot_out.txt" , FILE_READ);
296
+ if (bootFile) {
297
+ String existingContent;
298
+ while (bootFile.available ()) {
299
+ existingContent += char (bootFile.read ());
300
+ }
301
+ bootFile.close ();
302
+
303
+ // Compare existing content with new content
304
+ if (existingContent == newContent) {
305
+ return true ; // No need to overwrite
306
+ }
307
+ }
303
308
309
+ // Overwrite the file with new content
310
+ bootFile = wipperFatFs.open (" /wipper_boot_out.txt" , FILE_WRITE);
311
+ if (bootFile) {
312
+ bootFile.print (newContent);
304
313
bootFile.flush ();
305
314
bootFile.close ();
306
315
is_success = true ;
307
- } else {
308
- bootFile.close ();
309
316
}
317
+
310
318
return is_success;
311
319
}
312
320
0 commit comments