diff --git a/src/cmnds/cmd_if.c b/src/cmnds/cmd_if.c index 7b314ba5d..4fda4f21b 100644 --- a/src/cmnds/cmd_if.c +++ b/src/cmnds/cmd_if.c @@ -283,6 +283,12 @@ float getSunset(const char *s) { #endif + +float getRebootReason(const char *s) { + return g_rebootReason; +} + + const constant_t g_constants[] = { //cnstdetail:{"name":"MQTTOn", //cnstdetail:"title":"MQTTOn", @@ -470,6 +476,13 @@ const constant_t g_constants[] = { //cnstdetail:"descr":"Random unsigned value", //cnstdetail:"requires":""} { "$rand", &getRand }, +#ifdef PLATFORM_BEKEN + //cnstdetail:{"name":"$rebootReason", + //cnstdetail:"title":"$rebootReason", + //cnstdetail:"descr":"Reboot reason", + //cnstdetail:"requires":""} + { "$rebootReason", &getRebootReason }, +#endif }; static int g_totalConstants = sizeof(g_constants) / sizeof(g_constants[0]); diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index 11c9368b4..e193f8104 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -874,22 +874,20 @@ typedef enum { } RESET_SOURCE_STATUS; */ - int bk_misc_get_start_type(); { const char* s = "Unk"; - i = bk_misc_get_start_type(); - if (i == 0) + if (g_rebootReason == 0) s = "Pwr"; - else if (i == 1) + else if (g_rebootReason == 1) s = "Rbt"; - else if (i == 2) + else if (g_rebootReason == 2) s = "Wdt"; - else if (i == 3) + else if (g_rebootReason == 3) s = "Pin Interrupt"; - else if (i == 4) + else if (g_rebootReason == 4) s = "Sleep Timer"; - hprintf255(request, "
Reboot reason: %i - %s
", i, s); + hprintf255(request, "
Reboot reason: %i - %s
", g_rebootReason, s); } #elif PLATFORM_BL602 char reason[26]; diff --git a/src/new_common.h b/src/new_common.h index 8053c2425..e5828a859 100644 --- a/src/new_common.h +++ b/src/new_common.h @@ -484,6 +484,7 @@ extern int g_startPingWatchDogAfter; extern int g_openAP; extern int g_bootFailures; extern int g_secondsElapsed; +extern int g_rebootReason; typedef int(*jsonCb_t)(void *userData, const char *fmt, ...); int JSON_ProcessCommandReply(const char *cmd, const char *args, void *request, jsonCb_t printer, int flags); diff --git a/src/user_main.c b/src/user_main.c index 2d764cd89..2f8b90115 100644 --- a/src/user_main.c +++ b/src/user_main.c @@ -277,6 +277,7 @@ void Main_OnPingCheckerReply(int ms) int g_doHomeAssistantDiscoveryIn = 0; int g_bBootMarkedOK = 0; +int g_rebootReason = 0; static int bMQTTconnected = 0; int Main_HasMQTTConnected() @@ -894,6 +895,11 @@ void Main_Init_BeforeDelay_Unsafe(bool bAutoRunScripts) { #ifndef OBK_DISABLE_ALL_DRIVERS DRV_Generic_Init(); #endif +#ifdef PLATFORM_BEKEN + int bk_misc_get_start_type(); + g_rebootReason = bk_misc_get_start_type(); +#endif + RepeatingEvents_Init(); // set initial values for channels.