@mikrojs/firmware 0.16.0 → 0.17.0-next.20260722220623
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/mikrojs/CMakeLists.txt +9 -2
- package/components/mikrojs/include/mikrojs_esp32.h +23 -0
- package/components/mikrojs/mik_config.cpp +159 -5
- package/components/mikrojs/mik_deploy.cpp +54 -35
- package/components/mikrojs/mik_main.cpp +66 -5
- package/components/mikrojs/mik_nvs_kv.cpp +64 -18
- package/components/mikrojs/mik_ota.cpp +1791 -0
- package/components/mikrojs/platform_esp32.cpp +59 -0
- package/components/mikrojs/test/CMakeLists.txt +1 -0
- package/components/mikrojs/test/ble_test.cpp +2 -2
- package/components/mikrojs/test/fs_js_test.cpp +1 -1
- package/components/mikrojs/test/fs_pub_test.cpp +23 -23
- package/components/mikrojs/test/http_server_test.cpp +12 -2
- package/components/mikrojs/test/http_test.cpp +2 -2
- package/components/mikrojs/test/modules_extended_test.cpp +2 -2
- package/components/mikrojs/test/modules_test.cpp +2 -2
- package/components/mikrojs/test/nvs_kv_test.cpp +245 -0
- package/components/mikrojs/test/ota_host/gunzip_host_test.cpp +118 -0
- package/components/mikrojs/test/ota_host/run.sh +174 -0
- package/components/mikrojs/test/rtc_test.cpp +1 -1
- package/components/mikrojs/test/sleep_test.cpp +1 -1
- package/components/mikrojs/test/sntp_test.cpp +1 -1
- package/components/mikrojs/test/stdio_test.cpp +1 -1
- package/components/mikrojs/test/sys_test.cpp +1 -1
- package/components/mikrojs/test/udp_test.cpp +5 -5
- package/components/mikrojs/test/wifi_test.cpp +2 -2
- package/package.json +3 -3
- package/prebuilds/esp32/bootloader/bootloader.bin +0 -0
- package/prebuilds/esp32/mikrojs.bin +0 -0
- package/prebuilds/esp32c3/bootloader/bootloader.bin +0 -0
- package/prebuilds/esp32c3/mikrojs.bin +0 -0
- package/prebuilds/esp32c5/bootloader/bootloader.bin +0 -0
- package/prebuilds/esp32c5/mikrojs.bin +0 -0
- package/prebuilds/esp32c6/bootloader/bootloader.bin +0 -0
- package/prebuilds/esp32c6/mikrojs.bin +0 -0
- package/prebuilds/esp32s3/bootloader/bootloader.bin +0 -0
- package/prebuilds/esp32s3/mikrojs.bin +0 -0
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* native:mikro/nvs_kv — NVS-backed key-value storage native module.
|
|
3
3
|
*
|
|
4
|
-
* Values are CBOR-encoded and stored as NVS blobs in the
|
|
5
|
-
*
|
|
4
|
+
* Values are CBOR-encoded and stored as NVS blobs. App data lives in the
|
|
5
|
+
* "mik.kv" namespace (set/get/remove/clear); runtime-internal state lives
|
|
6
|
+
* in "mik.sys" (sysSet/sysGet/sysRemove/sysClear), never implicitly
|
|
7
|
+
* cleared. Survives power cycles. NVS keys are limited to 15 characters.
|
|
6
8
|
*/
|
|
7
9
|
|
|
8
10
|
#include <cstring>
|
|
@@ -16,12 +18,19 @@
|
|
|
16
18
|
#include "mikrojs/utils.h"
|
|
17
19
|
|
|
18
20
|
#define MIK_NVS_KV_NS "mik.kv"
|
|
21
|
+
#define MIK_NVS_SYS_NS "mik.sys"
|
|
19
22
|
#define MIK_NVS_MAX_KEY_LEN 15
|
|
20
23
|
#define MIK_NVS_MAX_VAL_LEN (16 * 1024)
|
|
21
24
|
|
|
25
|
+
/* magic selects the namespace: 0 = mik.kv (app data), 1 = mik.sys (runtime) */
|
|
26
|
+
static const char* mik__nvs_ns(int magic) {
|
|
27
|
+
return magic ? MIK_NVS_SYS_NS : MIK_NVS_KV_NS;
|
|
28
|
+
}
|
|
29
|
+
|
|
22
30
|
/* ── JS functions ────────────────────────────────────────────────── */
|
|
23
31
|
|
|
24
|
-
static JSValue mik__nvs_kv_set(JSContext* ctx, JSValue this_val, int argc, JSValue* argv
|
|
32
|
+
static JSValue mik__nvs_kv_set(JSContext* ctx, JSValue this_val, int argc, JSValue* argv,
|
|
33
|
+
int magic) {
|
|
25
34
|
const char* key = JS_ToCString(ctx, argv[0]);
|
|
26
35
|
if (!key) return JS_EXCEPTION;
|
|
27
36
|
size_t key_len = strlen(key);
|
|
@@ -58,7 +67,7 @@ static JSValue mik__nvs_kv_set(JSContext* ctx, JSValue this_val, int argc, JSVal
|
|
|
58
67
|
|
|
59
68
|
/* Write to NVS */
|
|
60
69
|
nvs_handle_t handle;
|
|
61
|
-
esp_err_t err = nvs_open(
|
|
70
|
+
esp_err_t err = nvs_open(mik__nvs_ns(magic), NVS_READWRITE, &handle);
|
|
62
71
|
if (err != ESP_OK) {
|
|
63
72
|
js_free(ctx, buf);
|
|
64
73
|
JS_FreeCString(ctx, key);
|
|
@@ -87,7 +96,8 @@ static JSValue mik__nvs_kv_set(JSContext* ctx, JSValue this_val, int argc, JSVal
|
|
|
87
96
|
return mik__result_ok_void(ctx);
|
|
88
97
|
}
|
|
89
98
|
|
|
90
|
-
static JSValue mik__nvs_kv_get(JSContext* ctx, JSValue this_val, int argc, JSValue* argv
|
|
99
|
+
static JSValue mik__nvs_kv_get(JSContext* ctx, JSValue this_val, int argc, JSValue* argv,
|
|
100
|
+
int magic) {
|
|
91
101
|
const char* key = JS_ToCString(ctx, argv[0]);
|
|
92
102
|
if (!key) return JS_EXCEPTION;
|
|
93
103
|
size_t key_len = strlen(key);
|
|
@@ -98,7 +108,7 @@ static JSValue mik__nvs_kv_get(JSContext* ctx, JSValue this_val, int argc, JSVal
|
|
|
98
108
|
}
|
|
99
109
|
|
|
100
110
|
nvs_handle_t handle;
|
|
101
|
-
if (nvs_open(
|
|
111
|
+
if (nvs_open(mik__nvs_ns(magic), NVS_READONLY, &handle) != ESP_OK) {
|
|
102
112
|
JS_FreeCString(ctx, key);
|
|
103
113
|
return JS_UNDEFINED;
|
|
104
114
|
}
|
|
@@ -139,12 +149,13 @@ static JSValue mik__nvs_kv_get(JSContext* ctx, JSValue this_val, int argc, JSVal
|
|
|
139
149
|
return result;
|
|
140
150
|
}
|
|
141
151
|
|
|
142
|
-
static JSValue mik__nvs_kv_remove(JSContext* ctx, JSValue this_val, int argc, JSValue* argv
|
|
152
|
+
static JSValue mik__nvs_kv_remove(JSContext* ctx, JSValue this_val, int argc, JSValue* argv,
|
|
153
|
+
int magic) {
|
|
143
154
|
const char* key = JS_ToCString(ctx, argv[0]);
|
|
144
155
|
if (!key) return JS_EXCEPTION;
|
|
145
156
|
|
|
146
157
|
nvs_handle_t handle;
|
|
147
|
-
if (nvs_open(
|
|
158
|
+
if (nvs_open(mik__nvs_ns(magic), NVS_READWRITE, &handle) != ESP_OK) {
|
|
148
159
|
JS_FreeCString(ctx, key);
|
|
149
160
|
return JS_NewBool(ctx, false);
|
|
150
161
|
}
|
|
@@ -162,16 +173,27 @@ static JSValue mik__nvs_kv_remove(JSContext* ctx, JSValue this_val, int argc, JS
|
|
|
162
173
|
return JS_NewBool(ctx, true);
|
|
163
174
|
}
|
|
164
175
|
|
|
165
|
-
static JSValue mik__nvs_kv_clear(JSContext* ctx, JSValue this_val, int argc, JSValue* argv
|
|
176
|
+
static JSValue mik__nvs_kv_clear(JSContext* ctx, JSValue this_val, int argc, JSValue* argv,
|
|
177
|
+
int magic) {
|
|
166
178
|
nvs_handle_t handle;
|
|
167
|
-
|
|
168
|
-
|
|
179
|
+
esp_err_t err = nvs_open(mik__nvs_ns(magic), NVS_READWRITE, &handle);
|
|
180
|
+
if (err != ESP_OK) {
|
|
181
|
+
return mik__result_err(ctx, MIK_ERR_KV_WRITE, err,
|
|
182
|
+
"NVS open failed: %s", esp_err_to_name(err));
|
|
169
183
|
}
|
|
170
184
|
|
|
171
|
-
nvs_erase_all(handle);
|
|
172
|
-
|
|
185
|
+
err = nvs_erase_all(handle);
|
|
186
|
+
if (err == ESP_OK) {
|
|
187
|
+
err = nvs_commit(handle);
|
|
188
|
+
}
|
|
173
189
|
nvs_close(handle);
|
|
174
|
-
|
|
190
|
+
|
|
191
|
+
if (err != ESP_OK) {
|
|
192
|
+
return mik__result_err(ctx, MIK_ERR_KV_WRITE, err,
|
|
193
|
+
"NVS clear failed: %s", esp_err_to_name(err));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return mik__result_ok_void(ctx);
|
|
175
197
|
}
|
|
176
198
|
|
|
177
199
|
static JSValue mik__nvs_kv_info(JSContext* ctx, JSValue this_val, int argc, JSValue* argv) {
|
|
@@ -197,10 +219,30 @@ static JSValue mik__nvs_kv_info(JSContext* ctx, JSValue this_val, int argc, JSVa
|
|
|
197
219
|
/* ── Module init ─────────────────────────────────────────────────── */
|
|
198
220
|
|
|
199
221
|
static int mik__nvs_kv_module_init(JSContext* ctx, JSModuleDef* m) {
|
|
200
|
-
JS_SetModuleExport(ctx, m, "set",
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
JS_SetModuleExport(ctx, m, "
|
|
222
|
+
JS_SetModuleExport(ctx, m, "set",
|
|
223
|
+
JS_NewCFunctionMagic(ctx, mik__nvs_kv_set, "set", 2,
|
|
224
|
+
JS_CFUNC_generic_magic, 0));
|
|
225
|
+
JS_SetModuleExport(ctx, m, "get",
|
|
226
|
+
JS_NewCFunctionMagic(ctx, mik__nvs_kv_get, "get", 1,
|
|
227
|
+
JS_CFUNC_generic_magic, 0));
|
|
228
|
+
JS_SetModuleExport(ctx, m, "remove",
|
|
229
|
+
JS_NewCFunctionMagic(ctx, mik__nvs_kv_remove, "remove", 1,
|
|
230
|
+
JS_CFUNC_generic_magic, 0));
|
|
231
|
+
JS_SetModuleExport(ctx, m, "clear",
|
|
232
|
+
JS_NewCFunctionMagic(ctx, mik__nvs_kv_clear, "clear", 0,
|
|
233
|
+
JS_CFUNC_generic_magic, 0));
|
|
234
|
+
JS_SetModuleExport(ctx, m, "sysSet",
|
|
235
|
+
JS_NewCFunctionMagic(ctx, mik__nvs_kv_set, "sysSet", 2,
|
|
236
|
+
JS_CFUNC_generic_magic, 1));
|
|
237
|
+
JS_SetModuleExport(ctx, m, "sysGet",
|
|
238
|
+
JS_NewCFunctionMagic(ctx, mik__nvs_kv_get, "sysGet", 1,
|
|
239
|
+
JS_CFUNC_generic_magic, 1));
|
|
240
|
+
JS_SetModuleExport(ctx, m, "sysRemove",
|
|
241
|
+
JS_NewCFunctionMagic(ctx, mik__nvs_kv_remove, "sysRemove", 1,
|
|
242
|
+
JS_CFUNC_generic_magic, 1));
|
|
243
|
+
JS_SetModuleExport(ctx, m, "sysClear",
|
|
244
|
+
JS_NewCFunctionMagic(ctx, mik__nvs_kv_clear, "sysClear", 0,
|
|
245
|
+
JS_CFUNC_generic_magic, 1));
|
|
204
246
|
JS_SetModuleExport(ctx, m, "info", JS_NewCFunction(ctx, mik__nvs_kv_info, "info", 0));
|
|
205
247
|
return 0;
|
|
206
248
|
}
|
|
@@ -212,6 +254,10 @@ static JSModuleDef* mik__nvs_kv_init(JSContext* ctx) {
|
|
|
212
254
|
JS_AddModuleExport(ctx, m, "get");
|
|
213
255
|
JS_AddModuleExport(ctx, m, "remove");
|
|
214
256
|
JS_AddModuleExport(ctx, m, "clear");
|
|
257
|
+
JS_AddModuleExport(ctx, m, "sysSet");
|
|
258
|
+
JS_AddModuleExport(ctx, m, "sysGet");
|
|
259
|
+
JS_AddModuleExport(ctx, m, "sysRemove");
|
|
260
|
+
JS_AddModuleExport(ctx, m, "sysClear");
|
|
215
261
|
JS_AddModuleExport(ctx, m, "info");
|
|
216
262
|
return m;
|
|
217
263
|
}
|