Skip to content

Commit ce86d41

Browse files
cpqcesantabot
authored andcommitted
Run app.js in addition to init.js
CL: Run app.js in addition to init.js PUBLISHED_FROM=2dafadc576a5f43bb76496d30234c2b4fcd3f862
1 parent 1cc6963 commit ce86d41

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/mos_mjs.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
#include "mgos_app.h"
2424
#include "mgos_dlsym.h"
25-
#include "mgos_hal.h"
2625
#include "mgos_event.h"
26+
#include "mgos_hal.h"
2727
#include "mgos_mongoose.h"
2828
#include "mgos_net.h"
2929
#include "mgos_sys_config.h"
@@ -35,18 +35,29 @@ struct mjs *mjs = NULL;
3535

3636
/*
3737
* Runs when all initialization (all libs + app) is done
38+
* Execute two files:
39+
* - init.js, which is supposed to be included in the firmware and thus
40+
* overridden by the OTA
41+
* - app.js, which is NOT supposed to be included in the FW and thus
42+
* it survives OTA.
43+
* For example, if you want to customize demo-js built-in firmware by your
44+
* own custom code that survives OTA, upload your own app.js to the device.
45+
* Then you can update the device and app.js will be preserved.
3846
*/
3947
static void s_init_done_handler(int ev, void *ev_data, void *userdata) {
4048
int mem1, mem2;
4149

4250
mem1 = mgos_get_free_heap_size();
43-
mjs_err_t err = mjs_exec_file(mjs, "init.js", NULL);
44-
if (err != MJS_OK) {
51+
LOG(LL_DEBUG, ("Trying to run init.js ..."));
52+
if (mjs_exec_file(mjs, "init.js", NULL) != MJS_OK) {
4553
mjs_print_error(mjs, stdout, NULL, 1 /* print_stack_trace */);
4654
}
55+
LOG(LL_DEBUG, ("Trying to run app.js ..."));
56+
if (mjs_exec_file(mjs, "app.js", NULL) != MJS_OK) {
57+
mjs_print_error(mjs, stdout, NULL, 1);
58+
}
4759
mem2 = mgos_get_free_heap_size();
48-
LOG(LL_DEBUG,
49-
("mJS memory stat: before init.js: %d after init.js: %d", mem1, mem2));
60+
LOG(LL_DEBUG, ("mJS RAM stat: before user code: %d after: %d", mem1, mem2));
5061

5162
(void) ev;
5263
(void) ev_data;

0 commit comments

Comments
 (0)