Here is the code which writes user input into enduser_custom_parameters.json file. This is part of enduser_setup module of esp8266/nodeMCU.
static int enduser_setup_write_file_with_extra_configuration_data(
char * configuration_string, int configuration_length
)
{
int p_file = 0;
lua_State *L = NULL;
ENDUSER_SETUP_DEBUG("enduser: opening enduser_custom_parameters.json for write");
// setup the file output
p_file = vfs_open("enduser_custom_parameters.json", "w");
if (p_file == 0)
{
ENDUSER_SETUP_DEBUG("Can't write to file!");
return 1;
}
/* Not certain what this does */
L = lua_getstate();
if (L != NULL)
{
lua_pushlstring(L, configuration_string, configuration_length);
}
vfs_write(p_file, configuration_string, configuration_length);
vfs_close(p_file);
return 0;
}
How should I modify this code to save the data into separate file each time? (I am modifying the module to act as Captive Portal to collect data from different users) I think I can use GUID, current date/time or user's MAC (ideal option) as filename. But have no idea how to do it with C.