diff --git a/src/cmnds/cmd_eventHandlers.c b/src/cmnds/cmd_eventHandlers.c index 78012d8ea..1338c934a 100644 --- a/src/cmnds/cmd_eventHandlers.c +++ b/src/cmnds/cmd_eventHandlers.c @@ -66,6 +66,10 @@ addEventHandler OnHold 11 addChannel 1 -10 // addChangeHandler Channel1 == 0 backlog lcd_clearAndGoto I2C1 0x23 1 1; lcd_print I2C1 0x23 Disabled +alias doRelayClick backlog setChannel 1 1; addRepeatingEvent 2 1 setChannel 1 0; ClearNoPingTime +addChangeHandler NoPingTime > 40 doRelayClick + + // This will automatically turn off relay after about 2 seconds // NOTE: addRepeatingEvent [RepeatTime] [RepeatCount] // addChangeHandler Channel0 != 0 addRepeatingEvent 2 1 setChannel 0 0 @@ -122,6 +126,8 @@ static int EVENT_ParseEventName(const char *s) { if(!wal_strnicmp(s,"channel",7)) { return CMD_EVENT_CHANGE_CHANNEL0 + atoi(s+7); } + if (!stricmp(s, "noPingTime")) + return CMD_EVENT_CHANGE_NOPINGTIME; if(!stricmp(s,"voltage")) return CMD_EVENT_CHANGE_VOLTAGE; if(!stricmp(s,"current")) diff --git a/src/cmnds/cmd_main.c b/src/cmnds/cmd_main.c index 2284c963f..e4ebdf78a 100644 --- a/src/cmnds/cmd_main.c +++ b/src/cmnds/cmd_main.c @@ -138,6 +138,10 @@ static commandResult_t CMD_ClearAll(const void *context, const char *cmd, const return CMD_RES_OK; } +static commandResult_t CMD_ClearNoPingTime(const void *context, const char *cmd, const char *args, int cmdFlags) { + g_timeSinceLastPingReply = 0; + return CMD_RES_OK; +} static commandResult_t CMD_ClearConfig(const void *context, const char *cmd, const char *args, int cmdFlags){ CFG_SetDefaultConfig(); @@ -207,6 +211,11 @@ void CMD_Init_Early() { //cmddetail:"fn":"CMD_Flags","file":"cmnds/cmd_main.c","requires":"", //cmddetail:"examples":""} CMD_RegisterCommand("flags", "", CMD_Flags, NULL, NULL); + //cmddetail:{"name":"ClearNoPingTime","args":"", + //cmddetail:"descr":"Command for ping watchdog; it sets the 'time since last ping reply' to 0 again", + //cmddetail:"fn":"CMD_ClearNoPingTime","file":"cmnds/cmd_main.c","requires":"", + //cmddetail:"examples":""} + CMD_RegisterCommand("ClearNoPingTime", "", CMD_ClearNoPingTime, NULL, NULL); #if (defined WINDOWS) || (defined PLATFORM_BEKEN) CMD_InitScripting(); diff --git a/src/cmnds/cmd_public.h b/src/cmnds/cmd_public.h index ab5ccfced..e6b1585a2 100644 --- a/src/cmnds/cmd_public.h +++ b/src/cmnds/cmd_public.h @@ -102,6 +102,8 @@ enum EventCode { CMD_EVENT_PIN_ON3CLICK, CMD_EVENT_PIN_ON4CLICK, + CMD_EVENT_CHANGE_NOPINGTIME, + // must be lower than 256 CMD_EVENT_MAX_TYPES }; diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index 1bc928f56..c1342481d 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -210,6 +210,7 @@ int http_fn_index(http_request_t* request) { float fValue; int iValue; bool bForceShowRGB; + const char* inputName; bRawPWMs = CFG_HasFlag(OBK_FLAG_LED_RAWCHANNELSMODE); bForceShowRGBCW = CFG_HasFlag(OBK_FLAG_LED_FORCESHOWRGBCWCONTROLLER); @@ -619,7 +620,7 @@ int http_fn_index(http_request_t* request) { else if ((bRawPWMs && h_isChannelPWM(i)) || (channelType == ChType_Dimmer) || (channelType == ChType_Dimmer256) || (channelType == ChType_Dimmer1000)) { int maxValue; // PWM and dimmer both use a slider control - const char* inputName = h_isChannelPWM(i) ? "pwm" : "dim"; + inputName = h_isChannelPWM(i) ? "pwm" : "dim"; int pwmValue; if (channelType == ChType_Dimmer256) { @@ -672,7 +673,6 @@ int http_fn_index(http_request_t* request) { if (c_pwms > 0) { int pwmValue; - const char* inputName; inputName = "dim"; @@ -688,7 +688,7 @@ int http_fn_index(http_request_t* request) { } if (c_pwms >= 3) { char colorValue[16]; - const char* inputName = "rgb"; + inputName = "rgb"; const char* activeStr = ""; if (lm == Light_RGB) { activeStr = "[ACTIVE]"; @@ -706,7 +706,6 @@ int http_fn_index(http_request_t* request) { if (c_pwms == 2 || c_pwms >= 4) { // TODO: temperature slider int pwmValue; - const char* inputName; const char* activeStr = ""; if (lm == Light_Temperature) { activeStr = "[ACTIVE]"; @@ -766,8 +765,17 @@ int http_fn_index(http_request_t* request) { hprintf255(request, "
Cfg size: %i, change counter: %i, ota counter: %i, boot incompletes %i (might change to 0 if you wait to 30 sec)!
", sizeof(g_cfg), g_cfg.changeCounter, g_cfg.otaCounter, Main_GetLastRebootBootFailures()); - hprintf255(request, "
Ping watchdog - %i lost, %i ok!
", - PingWatchDog_GetTotalLost(), PingWatchDog_GetTotalReceived()); + inputName = CFG_GetPingHost(); + if (inputName && *inputName) { + hprintf255(request, "
Ping watchdog (%s) - ", inputName); + if (g_startPingWatchDogAfter > 0) { + hprintf255(request, "will start in %i!
", g_startPingWatchDogAfter); + } + else { + hprintf255(request, "%i lost, %i ok, last reply was %is ago!", + PingWatchDog_GetTotalLost(), PingWatchDog_GetTotalReceived(), g_timeSinceLastPingReply); + } + } if (Main_HasWiFiConnected()) { hprintf255(request, "
Wifi RSSI: %s (%idBm)
", str_rssi[wifi_rssi_scale(HAL_GetWifiStrength())], HAL_GetWifiStrength()); diff --git a/src/new_common.h b/src/new_common.h index 9902dbe40..f237df9ae 100644 --- a/src/new_common.h +++ b/src/new_common.h @@ -394,7 +394,6 @@ void Main_OnPingCheckerReply(int ms); // new_ping.c void Main_SetupPingWatchDog(const char *target/*, int delayBetweenPings_Seconds*/); -void Main_PingWatchDogSilent(); int PingWatchDog_GetTotalLost(); int PingWatchDog_GetTotalReceived(); @@ -422,6 +421,8 @@ typedef enum WIFI_RSSI_LEVEL wifi_rssi_scale(int8_t rssi_value); extern const char *str_rssi[]; extern int bSafeMode; +extern int g_timeSinceLastPingReply; +extern int g_startPingWatchDogAfter; #endif /* __NEW_COMMON_H__ */ diff --git a/src/new_ping.c b/src/new_ping.c index 2a245efbd..5f417e8ae 100644 --- a/src/new_ping.c +++ b/src/new_ping.c @@ -120,7 +120,7 @@ static void ping_timeout(void *arg) { struct raw_pcb *pcb = (struct raw_pcb*)arg; - if (ping_handler_silent == false) + // if (ping_handler_silent == false) { LWIP_ASSERT("ping_timeout: no pcb given!", pcb != NULL); @@ -172,6 +172,7 @@ int PingWatchDog_GetTotalLost() { int PingWatchDog_GetTotalReceived() { return ping_received; } + void Main_SetupPingWatchDog(const char *target/*, int delayBetweenPings_Seconds*/) { // none sent yet. @@ -190,14 +191,8 @@ void Main_SetupPingWatchDog(const char *target/*, int delayBetweenPings_Seconds* raw_bind(ping_pcb, IP_ADDR_ANY); // void sys_timeout (u32_t msecs, sys_timeout_handler handler, void *arg) sys_timeout(PING_DELAY, ping_timeout, ping_pcb); + ping_handler_active = true; } - ping_handler_active = true; - ping_handler_silent = false; } -void Main_PingWatchDogSilent() -{ - ping_handler_silent = true; -} - diff --git a/src/new_pins.c b/src/new_pins.c index 359b453ca..57a0f5df8 100644 --- a/src/new_pins.c +++ b/src/new_pins.c @@ -769,8 +769,12 @@ void PIN_SetGenericDoubleClickCallback(void (*cb)(int pinIndex)) { void Channel_SaveInFlashIfNeeded(int ch) { // save, if marked as save value in flash (-1) if(g_cfg.startChannelValues[ch] == -1) { + //addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "Channel_SaveInFlashIfNeeded: Channel %i is being saved to flash, state %i", ch, g_channelValues[ch]); HAL_FlashVars_SaveChannel(ch,g_channelValues[ch]); } + else { + //addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "Channel_SaveInFlashIfNeeded: Channel %i is not saved to flash, state %i", ch, g_channelValues[ch]); + } } static void Channel_OnChanged(int ch, int prevValue, int iFlags) { int i; @@ -846,8 +850,10 @@ void CFG_ApplyChannelStartValues() { iValue = g_cfg.startChannelValues[i]; if(iValue == -1) { g_channelValues[i] = HAL_FlashVars_GetChannelValue(i); + //addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "CFG_ApplyChannelStartValues: Channel %i is being set to REMEMBERED state %i", i, g_channelValues[i]); } else { g_channelValues[i] = iValue; + //addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "CFG_ApplyChannelStartValues: Channel %i is being set to constant state %i", i, g_channelValues[i]); } } } diff --git a/src/user_main.c b/src/user_main.c index 3e5f46be8..78f148a89 100644 --- a/src/user_main.c +++ b/src/user_main.c @@ -59,12 +59,12 @@ static int g_bOpenAccessPointMode = 0; static int g_doUnsafeInitIn = 0; int g_bootFailures = 0; static int g_saveCfgAfter = 0; -static int g_startPingWatchDogAfter = 0; +int g_startPingWatchDogAfter = 60; // many boots failed? do not run pins or anything risky int bSafeMode = 0; // not really