Current Lua downloadable firmware will be posted here

User avatar
By beckmx
#9561 Hello guys, I have been using nodemcu but I would like to know what available space I have to program, I have seen lots of numbers in the web but at the end I still don't know which one is the correct, at least I have learned that heap is to get available ram available but not the freespace available.

Greetings!
User avatar
By kirsch
#10470 It's hard to say "what available space" you have. As far as I can tell, using a recent build, you have around 20 KB of free memory. If you use a version of the firmware without floating point, you can get a few KB more. It would be useful to have some tips on how to build the firmware leaving some features in or out.

Lua code will use varying amounts of memory based on what it is and what it is doing. If you want your code to be more efficient then use "local" to declare variables when possible and call node.compile("yourfile.lua"). Compiled lua code uses less memory.

Good luck, so far I have found that there's not a lot of memory available for scripts and what you can do is quite limited.
User avatar
By dpwhittaker
#10483 I wrote an extension to file to report the total space and the free space, and got some interesting results.

There is about 120kb free when the file system is first formatted.
Due to wear levelling (I guess), spiffs quickly uses up the free blocks, so you have all the blocks used with only a few pages in use on each one.
As you add files, spiffs looks for a block with free space and writes the file there.
If the block doesn't have enough free pages, spiffs seems to fill up the block and just quit writing the file.
Files can only span a few logical blocks?
So, unless you are using a bunch of 240 byte files, it can be difficult to actually use all that free space.

Now, it is quite possible that I am misunderstanding the data spiffs is providing, but a little bit of experimentation seems to hold up.

If you are interested, this is how I extended file.c in app/modules:

Code: Select allstatic int file_freespace (lua_State *L)
{
  lua_pushinteger(L, fs.block_count * fs.cfg.phys_erase_block - fs.stats_p_allocated * fs.cfg.log_page_size);
  return 1;
}

static int file_totalspace (lua_State *L)
{
  lua_pushinteger(L, fs.block_count * fs.cfg.phys_erase_block);
  return 1;
}


It's probably counting logical blocks instead of physical blocks, but it doesn't matter because they are set the same.

Either way, when I got to about half the free space used, I started having trouble writing large files completely. As I added more small files, free space started acting erratically. Maybe the allocated pages include pages marked for deletion. I'll keep trying to get better understanding, but right now, it looks like the file system isn't able to use all the free space it has.
User avatar
By alonewolfx2
#10494 i tried your code but it seems missing something. i have this error message when compiling.
Code: Select allfile.c:48:22: error: 'fs' undeclared (first use in this function)