-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
NewFeature / Technique
I am not sure whether is an application note or an example of an add-on project but I thought that I should raise this issue to get feedback from the other contributors
Justification
At them moment we need a filesystem in place and some files downloaded to be able to bootstrap up and provision a new module. Whilst this can be done using esptool and other downloaders, these are not project maintained and so for many developers who are tooled up with python, spiffsimg, etc. getting your project bootstrapped can involve some hurdles.
I have been experimenting with an alternative bootstrapping approach that might have some merit (I am actually using it on my automated test harness.) In essence I have taken a set of modules, run them through LuaSrcDiet and then convert the output compressed Lua source a C string and included them into a C module, so that fast.load('name')
returns an albeit RAM-based module name
:
static int fast_load (lua_State *L) {
static const char *const opts[] = {"HTTPloadfile", "telnet", "hello", NULL};
static const int optsnum[] = {0, 1, 2 };
static const char *const src[] = {HTTPLOADFILE, TELNET, HELLO};
int i = luaL_checkoption(L, 1, "HTTPloadfile", opts);
int status = luaL_loadbuffer(L, src[i], strlen(src[i]), opts[i]);
if (status != LUA_OK) lua_error(L);
return 1;
}
My current fast module adds about 4Kb to the image. So:
- You can use fast modules without LFS or a file system set up.
- You would typically start one up interactively or use the
node.startupcommand()
to do this automatically after boot. Sofast.load'telnet'(ssid,pwd)
will start up a telnet server, for example. - The module only uses RAM resources if you fast load it.
Squashed Lua is incredibly dense (the C string containing the telnet server is under 1Kb Flash).
At this moment my ideas are very much in a formative stage, but I have floated this for feedback and comment. See my gist Fash Lua module loader.
I am also going to look at adding an FTP implementation, but the current version is really designed to run out of LFS, I need to tweak this to do some lazy loading to reduce the RAM footprint for RAM only running.