diff --git a/README.md b/README.md index e50fe11..091f993 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,17 @@ this repo: ```sh $ make -C posix ARGS="-pass DEVICE_MDASH_PASSWORD" ``` + +Firmware V1.2.17: + +1. Resolved the bug on [mDashShadowUpdate()](https://github.com/cesanta/mDash/issues/22). +2. Added mDashNotify_shdw() for mDashShadowUpdate() with removal of MutexLock. + +Firmware V1.2.17X2: + +1. Added a function mDashOTAPercent() + +Firmware V1.2.17X3: + +1. Resolved the Mdash task exit when using mDashNotify(). +2. Removed the Mutex locks in mDashNotify() diff --git a/library.properties b/library.properties index deff451..2055e94 100644 --- a/library.properties +++ b/library.properties @@ -1,10 +1,10 @@ name=mDash -version=1.2.16 +version=1.2.17X3 author=Cesanta Software Limited maintainer=Cesanta Software Limited sentence=Remote control and OTA for ESP32 via mdash.net IoT backend paragraph=Provides OTA, MQTT, device shadow, Filesystem management for ESP32 category=Communication -url=https://github.com/cesanta/mDash +url=https://github.com/Thermelgy-Repo/mDash architectures=esp32 includes=mDash.h diff --git a/src/mDash.c b/src/mDash.c index 19add28..6a6ec79 100644 --- a/src/mDash.c +++ b/src/mDash.c @@ -398,7 +398,7 @@ static void rpc_fs_list(struct mg_rpc_req *r) { int mDashNotify(const char *name, const char *fmt, ...) { int res = 0; - MDashMutexLock(); + //MDashMutexLock(); va_list ap; if (s_conn != NULL) { struct mg_iobuf io = {0, 0, 0, 512}; @@ -413,7 +413,36 @@ int mDashNotify(const char *name, const char *fmt, ...) { mg_iobuf_free(&io); res = 1; } - MDashMutexUnlock(); + //MDashMutexUnlock(); + return res; +} + +/** + * @brief MDash Notify Shadow without mutex lock + * + * @param name Type Name + * @param fmt Format + * @param ... multiple arguments + * @return int + */ +int mDashNotify_shdw(const char *name, const char *fmt, ...) { + int res = 0; + //MDashMutexLock(); + va_list ap; + if (s_conn != NULL) { + struct mg_iobuf io = {0, 0, 0, 512}; + mg_rprintf(mg_pfn_iobuf, &io, "{%Q:%Q,%Q:", "method", name, "params"); + va_start(ap, fmt); + mg_vrprintf(mg_pfn_iobuf, &io, fmt, &ap); + va_end(ap); + mg_rprintf(mg_pfn_iobuf, &io, "}"); + if (io.buf != NULL) { + mg_ws_send(s_conn, (char *) io.buf, io.len, WEBSOCKET_OP_TEXT); + } + mg_iobuf_free(&io); + res = 1; + } + //MDashMutexUnlock(); return res; } @@ -790,3 +819,10 @@ void mDashInit(const char *id, const char *pass, const char *name, xTaskCreatePinnedToCore(&mDashTask, "mDashTask", 16384, 0, 5, 0, CPU_CORE); MDashMutexUnlock(); } + +int mDashOTAPercent(void){ + if (s_ota_size == 0) + return 0; // Or an error code if you prefer + + return((int) (s_ota_written * 100 / s_ota_size)); +} \ No newline at end of file diff --git a/src/mDash.h b/src/mDash.h index 0b7b7bc..4576610 100644 --- a/src/mDash.h +++ b/src/mDash.h @@ -38,6 +38,10 @@ int mDashStore(const char *topic, const char *json_fmt, ...); // Send notification frame to mDash int mDashNotify(const char *name, const char *fmt, ...); + +// Send notification of shadow to Mdash without Mutex lock +int mDashNotify_shdw(const char *name, const char *fmt, ...); + #define mDashShadowUpdate(fmt, ...) \ mDashNotify("Dash.Shadow.Update", (fmt), __VA_ARGS__) @@ -45,6 +49,7 @@ int mDashConfigGet(const char *name, char *buf, int bufsize); int mDashConfigSet(const char *name, const char *value); int mDashConfigReset(void); void mDashPoll(void); +int mDashOTAPercent(void); // Registered RPC handlers. Use mg_rpc_add() to add new handlers extern struct mg_rpc *g_rpcs;