22
22
23
23
#include "mgos_app.h"
24
24
#include "mgos_dlsym.h"
25
- #include "mgos_hal.h"
26
25
#include "mgos_event.h"
26
+ #include "mgos_hal.h"
27
27
#include "mgos_mongoose.h"
28
28
#include "mgos_net.h"
29
29
#include "mgos_sys_config.h"
@@ -35,18 +35,29 @@ struct mjs *mjs = NULL;
35
35
36
36
/*
37
37
* 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.
38
46
*/
39
47
static void s_init_done_handler (int ev , void * ev_data , void * userdata ) {
40
48
int mem1 , mem2 ;
41
49
42
50
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 ) {
45
53
mjs_print_error (mjs , stdout , NULL , 1 /* print_stack_trace */ );
46
54
}
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
+ }
47
59
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 ));
50
61
51
62
(void ) ev ;
52
63
(void ) ev_data ;
0 commit comments