ESP32 "fs" examples not working as expected. #6897
Replies: 1 comment
-
Posted at 2017-08-26 by Robin @user80339,
It appears the snippet is reading and writing to a file as expected, but the snippet is not identical to the code example at http://www.espruino.com/ESP32 Would you please post your code in it's entirety as one legible code block so that we may determine the differences between that shown in the above page and that in the snippet that is proving difficult. Posted at 2017-08-28 by miCatotonic Thank you for the response.
I put a couple of print statements in to delineate where the memory table should be printed. Posted at 2017-08-28 by Robin Thank you for posting a more legible sample. Allows for easier cut-n-paste I originally thought I spotted a case typo, but double checking the online reference proved otherwise. Anyone else able to chime in? Are lines 11 and 13 actually printing what is shown as a comment or are the comments leftover from the sample? Posted at 2017-08-28 by Wilberforce Hi @user80339, I have updated the docs, your code needs to look like this:
If the filesystem is attempted to be read and can't, then the filesystem is created. Please note that this only needs to occur once. If the flash memory is erased, them you will need to format again. The try/catch above prevents Posted at 2017-08-28 by miCatotonic @robin, Thank you for the feedback. You did catch a typo. I found and changed it while redoing my post. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-08-25 by miCatotonic
My Goal is to be able to use the ESP32 to serve a React.js or Vue.js single page app. Then use WS to communicate to back to the ESP32. The SPA file will eventually be over 2 Megs. But for now I just want to serve a html file out of the flash file system using the FAT protocol.
When trying to use example code from the espruin0.com/ESP32 page, none of the following works as is shown in the example.
console.log(require( "Flash").getFree());
var fs = require("fs");
if ( typeof(fs.readdirSync()) === 'undefined' ) {
console.log('Formatting FS');
E.flashFatFS({ format: true });
}
fs.writeFileSync("hello.txt", "Hello World");
console.log(fs.readFileSync("hello.txt")); // prints "Hello World"
fs.appendFileSync("hello.txt", "!!!");
console.log(fs.readFileSync("hello.txt")); // prints "Hello World!!!"
The results I get are:
For the "console.log(require( "Flash").getFree());" command:
[
{ "addr": 1114112, "length": 3080191 }
]
For the rest of the code:
Uncaught Error: Unable to mount media : NO_FILESYSTEM
at line 6 col 28
if ( typeof(fs.readdirSync()) === 'undefined' ) {
I am relatively new so there is a strong chance I am doing something wrong.
Beta Was this translation helpful? Give feedback.
All reactions