logo elektroda
logo elektroda
X
logo elektroda

BK7231N Tuya Smart Plug: Ping Watchdog Delayed Start & Detection Issues

tinkertechie 1563 12
ADVERTISEMENT
  • #1 20930947
    tinkertechie
    Level 2  

    I'm experimenting with using ping watchdog to monitor a device and reboot it when it becomes unresponsive - a common task. I'm using one of the older 7231 based Tuya "smart plug" devices.

    The strategy I'm taking is:

    - turn the relay on at startup
    - configure ping watchdog target and frequency
    - wait for WiFi to connect
    - wait for ping watchdog to start
    - wait for no-ping times to fall below a threshold (to ensure that the target device has finished startup)
    - wait for no-ping times to rise above a threshold (to determine if it's crashed)
    - turn off relay
    - wait 5 seconds
    - reboot.


    As a test device, I'm just using my phone as the ping target, and I'm finding that the ping watchdog is taking ages to start - many minutes. The log shows lines like this:

    Info:MAIN:Time 29, idle 192959/s, free 73760, MQTT 0(2), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 31, idle 189275/s, free 73760, MQTT 0(2), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 32, idle 186685/s, free 73760, MQTT 0(2), bWifi 1, secondsWithNoPing -1, socks 2/38

    From digging through the code, I can see that it doesn't try to start until 30 seconds after a successful WiFi connection and reports secondsWithNoPing of -1 until it does. What I'm seeing is the -1 for many minutes after WiFi connects.

    Is this the same value reported in scripts by noPingTime? Because I'm not succeeding in testing for the value being < 0.
  • ADVERTISEMENT
  • #2 20931042
    p.kaczmarek2
    Moderator Smart Home
    I've configured non existent IP:
    Configuration screen for the ping watchdog mechanism for the BK7231T device.
    And restarted the device, after an initial delay designed to give things time to settle I get:
    Screenshot showing a log with informational messages regarding network configuration.
    Now you can use:
    
    // events to run when no ping happens
    addChangeHandler noPingTime > 600 reboot
    

    to run an event

    PS: Here is a delayed start condition:
    Screenshot of code snippet showing a ping condition for rebooting a device after a time.

    Did you restart your device after configuration change?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #3 20931295
    tinkertechie
    Level 2  
    Hi, thanks for the amazingly quick reply!

    Yes, restarted after every code modification.

    Your log perfectly demonstrates the problem I'm concerned about. If the device hasn't completed its startup for whatever reason (just slow?) and can't reply, it's possible that noPingTime could become quite large before the script sees its first reply. The script could then assume that the device needs to be rebooted, but the script just needs to wait longer.

    I think I've got enough to work on from your reply, so I'll try something out and get back to you.

    Thanks again!
  • ADVERTISEMENT
  • #4 20931330
    p.kaczmarek2
    Moderator Smart Home
    tinkertechie wrote:

    Your log perfectly demonstrates the problem I'm concerned about. If the device hasn't completed its startup for whatever reason (just slow?) and can't reply, it's possible that noPingTime could become quite large before the script sees its first reply. The script could then assume that the device needs to be rebooted, but the script just needs to wait longer.

    I am not sure if I understand. Can you elaborate?

    tinkertechie wrote:
    If the device hasn't completed its startup for whatever reason (just slow?) and can't reply, it's possible that noPingTime could become quite large before the script sees its first reply.

    Which device? OBK or a target device?

    The whole idea is that you choose a certain margin, like a 30 seconds, and you just assume if 30 seconds should be enough for the device boot, and trigger event when noPingTime exceeds 30 seconds.

    How long does it take for your target device to reboot?

    Is your target device uptime so crucial that you are trying to optimize the downtime by choosing as small as possible noPingTime threshold?

    I can update SDK per your request to suit your needs but I need to get a better understanding of your use case.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #5 20931365
    tinkertechie
    Level 2  
    >>20931042
    I might have found the problem I'm facing...

    Basically, I want to be certain that the device has come up before I proceed. So if I delay for 15 seconds, THEN wait until secondsWithNoPing is below 10, I know for a fact that the device has actually responded at least once. I've been using

    "SetChannel 9 noPingTime"

    to try to see its value, but regardless of what the log is showing for secondsWithNoPing, Channel 9 is always being set to 0.

    Is noPingTime only exposed to AddChangeHandler, or is it also exposed to WaitFor, If statements, SetChannel, etc?

    ie: are any of the following valid?

    WaitFor noPingTime > 1

    If (noPingTime > 1) then goto xyz

    SetChannel 9 noPingTime


    Do I HAVE to craft this hold for a short ping time by establishing an AddChangeHandler? That's ok, I can do it, but it's a little cumbersome.
  • #6 20931383
    p.kaczmarek2
    Moderator Smart Home
    WaitFor syntax does not require a comparison sign, it should work in your case. I have updated our sample codes list in a reply to your request:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/autoexecExamples.md
    I've added a sample for WaitFor:
    
    // Example autoexec.bat usage
    // wait for ping watchdog alert when target host does not reply for 100 seconds:
    
    // do anything on startup
    startDriver NTP
    startDriver SSDP
    
    // setup ping watchdog
    PingHost 192.168.0.123
    PingInterval 10
    
    // WARNING! Ping Watchdog starts after a delay after a reboot.
    // So it will not start counting to 100 immediatelly
    
    // wait for NoPingTime reaching 100 seconds
    waitFor NoPingTime 100
    echo Sorry, it seems that ping target is not replying for over 100 seconds, will reboot now!
    // delay just to get log out
    delay_s 1
    echo Reboooooting!
    // delay just to get log out
    delay_s 1
    echo Nooow!
    reboot
    

    Would the following approach suit your needs, or shall we try exposing noPingTime more?

    EDIT: It sounds like you're looking a for an inverse waitFor....

    Added after 4 [minutes]:

    The idea to support comparison in waitFor seems very interesting:
    
    WaitFor noPingTime > 1
    

    I think I could make this work before tomorrow. I like that, from what I can see, it would require just few more lines of code.

    Can you wait?
    Helpful post? Buy me a coffee.
  • #7 20932837
    tinkertechie
    Level 2  

    Yes, that's almost exactly what I'm hoping for!

    The example for the AddChangeHandler for noPingTime includes a comparison - specifically ">".

    Basic Ping Watchdog usage with sample autoexec.bat script

    In testing it seems that it doesn't actually use this. I have tried clearing handlers and making a second call of "AddChangeHandler noPingTime < 10 SetChannel 10 2" but it doesn't seem to work. However, it MAY have been because, when I added the handler, noPingTime was already less than 10. Thus there was no change to trigger it.

    But, the ability to use WaitFor noPingTime < 10 would make some of what I'm trying to achieve a LOT easier.

    To reply to your previous request for clarification - yes, if the target host is slow to boot. I want to be 100% certain that the host has come up, so I don't somehow attempt a power cycle when the target is actually behaving itself! This is all prompted by a site where I'm waiting on a bug fix from an OEM who I don't want to embarrass publicly. But there are two devices on site that are affected. One is the router/AP and the other is an internal device that, for unknown but apparently related reasons, is also occasionally locking up.

    I am trying to reboot the devices when they lock up. I'll lose WiFi if the router/AP locks up, but for the other device I don't want to unnecessarily reboot it if the cause for loss of ping is the loss of router/AP WiFi. So I need to be able to differentiate. I suppose I can do that by inspecting WiFiState.

    Perhaps one solution would be to give expansions for noPingTime and WiFiState etc along the lines of $noPingTime and $WiFiState which would allow them to be used in "if" statements?

    As for waiting - well, obviously I'm able to wait because I can't do anything else :D The client is getting very irritated, but I'll be there tomorrow trying to pursue proper fixes rather than workarounds, which will keep them happy. But I'm not optimistic about that, so whenever you're able to get to this it would be fantastic. But I respect your situation and that this is presumably not your income source, so I don't want to make any demands!
  • #8 20933018
    p.kaczmarek2
    Moderator Smart Home
    tinkertechie wrote:

    The example for the AddChangeHandler for noPingTime includes a comparison - specifically ">".

    In testing it seems that it doesn't actually use this. I have tried clearing handlers and making a second call of "AddChangeHandler noPingTime < 10 SetChannel 10 2" but it doesn't seem to work. However, it MAY have been because, when I added the handler, noPingTime was already less than 10. Thus there was no change to trigger it.

    I think that change handlers by design are called only when the threshold is passed, just as you guessed. As in the title, the "change" has to occur.


    tinkertechie wrote:

    But, the ability to use WaitFor noPingTime < 10 would make some of what I'm trying to achieve a LOT easier.

    Ok, here it is, just remember, it only supports those 3 operators I listed in docs.
    Implementation:
    https://github.com/openshwprojects/OpenBK7231...mmit/2d78c6135e86d59f3848b0d164a1c5844e89f9af
    Self test:
    https://github.com/openshwprojects/OpenBK7231...mmit/ca926ef681f4b22932e85a20908d0fbf75acdf9e
    Docs:
    https://github.com/openshwprojects/OpenBK7231...mmit/3e0e321a010e9c8af233ba2ee36fbc32b14f62dd
    Copy of above:
    
    // Waitfor syntax samples
    // WaitFor can support following operators:
    // - no operator (default, it means equals)
    // - operator < (less)
    // - operator > (more)
    // - operator ! (not requal)
    
    // default usage - wait for NoPingTime to reach exact value 100
    waitFor NoPingTime 100
    
    // extra operator - wait for NoPingTime to become less than 100
    // (this will be triggered anytime variable changes to value less than 100)
    waitFor NoPingTime < 100
    
    // extra operator - wait for NoPingTime to become more than 100
    // (this will be triggered anytime variable changes to value more than 100)
    waitFor NoPingTime > 100
    
    // extra operator - wait for NoPingTime to become different than 100
    // (this will be triggered anytime variable changes to value other than 100)
    waitFor NoPingTime ! 100
    

    In this particular case, the waitFor will act a bit different than change handler, because change handler occurs only when a condition changes from false to true, and waitFor will trigger for any value that meets condition.



    tinkertechie wrote:

    Perhaps one solution would be to give expansions for noPingTime and WiFiState etc along the lines of $noPingTime and $WiFiState which would allow them to be used in "if" statements?

    I can do that as well, altough, the mechanism behind the expansions is different than the event system. Events are cast when something happen, and expansion happens per-request in place.


    tinkertechie wrote:

    As for waiting - well, obviously I'm able to wait because I can't do anything else :D The client is getting very irritated, but I'll be there tomorrow trying to pursue proper fixes rather than workarounds, which will keep them happy.

    You always have a second option, you can just draft a simple driver in C, we have online builds, you can build on Github, there is no need for even setting up a compiler on your machine.

    tinkertechie wrote:

    But I'm not optimistic about that, so whenever you're able to get to this it would be fantastic. But I respect your situation and that this is presumably not your income source, so I don't want to make any demands!

    Yes, it's a fully non-profit project, and donations are rare, even if 1 of 10 people reading this posts were to donate some $ to our paypal https://www.paypal.com/paypalme/openshwprojects it would already make a big difference and allow more development.
    Helpful post? Buy me a coffee.
  • #9 20934065
    tinkertechie
    Level 2  
    Thanks for the changes and the advice. I'd be happy to do a few test builds, so I'll have to learn more about how to do that on GitHub. I've got the repository cloned locally so I can look through the code more easily, and I'll have to play to see how the expansion might be achieved. It would be very useful.

    Another useful feature might be a timeout for WaitFor. I'll look into how to achieve that.

    Added after 1 [hours] 13 [minutes]:

    >>20933018
    I don't think it's quite working, or I'm doing something wrong. I can't find a way to directly inspect the value of noPingTime though for debugging so it's hard to tell.

    As you can see, Channel 8 never gets set to '2' - the code doesn't seem to advance past the "WaitFor noPingTime > 1".

    The "Channel 10" mechanism you see is how I was trying to implement this using addEventHandler. It's still in place for the final reboot, but we never get that far.

    You'll have to forgive me for not yet knowing how to drive the editor here properly, but this is the script, followed by the log:

    ---------------8<-----------------------
    // Set up a couple of basic useful events. In particular, give a quick way to get back to SafeMode

    alias myEvents backlog clearAllHandlers; addEventHandler On4Click 26 SafeMode 1; addEventHandler On3Click 26 reboot
    myEvents

    // Turn on the relay to start booting the monitored device
    SetChannel 1 1

    // Clear the flag we will use to indicate that it's time to move to the next phase
    SetChannel 10 0

    // set up ping monitoring. It won't start until some time after WiFi connects - source code implies 30 seconds later.

    PingHost XX.XX.XX.148
    PingInterval 5

    // wait for wifi to become WIFI_STA_CONNECTED
    waitFor WiFiState 4

    // give the browser log display a moment to connect
    delay_s 10

    // drop a mark in the log
    SetChannel 8 1

    // now wait for the ping monitoring to start

    WaitFor noPingTime > 1

    // drop a mark in the log
    SetChannel 8 2

    // Once pings are working, wait 15 seconds so we know we've tried to ping at least twice
    delay_s 15

    // now wait until we see that the target is up
    WaitFor noPingTime < 10

    // drop a mark in the log
    SetChannel 8 6

    // now that we know the target is up, set up the event to reboot
    myEvents
    addChangeHandler noPingTime > 30 SetChannel 10 9
    SetChannel 10 0

    sleepy9:
    delay_s 2
    // drop a mark in the log
    SetChannel 8 7
    if 9==$CH10 then goto restarttarget
    goto sleepy9

    // Turn off the power to the target, then reboot after 5 seconds. The power is turned on again when this
    // script restarts. There seems to be a bug where the delay is ignored if it is the last step in the script.
    // Need to investigate that further.
    restarttarget:

    SetChannel 1 0
    delay_s 5
    SetChannel 1 0

    reboot
    ---------------8<-----------------------


    And this is the log.:


    ---------------8<-----------------------
    Info:GEN:26 key_triple_press
    Info:EVENT:EventHandlers_FireEvent: executing command reboot
    Info:CMD:CMD_Restart: will reboot in 3
    Info:MAIN:Time 58, idle 190635/s, free 73576, MQTT 0(3), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Module reboot in 2...
    Info:MAIN:Time 12, idle 187627/s, free 73696, MQTT 0(0), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MQTT:mqtt_host empty, not starting mqtt
    Info:MAIN:Time 13, idle 187834/s, free 73696, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 14, idle 189463/s, free 73696, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 20, idle 191001/s, free 73696, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:GEN:dhcp=0 ip=XXXXXXX.112 gate=XXXXXXX.1 mask=255.255.255.0 mac=XXXXXXX
    Info:GEN:sta: 1, softap: 0, b/g/n
    Info:GEN:sta:rssi=-30,ssid=XXXXXXX,bssid=XXXXXXX,channel=11,cipher_type:CCMP
    Info:MAIN:Time 21, idle 185775/s, free 73696, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:GEN:CHANNEL_Set channel 8 has changed to 1 (flags 0)

    Info:MQTT:Channel has changed! Publishing 1 to channel 8
    Info:MAIN:Time 24, idle 191402/s, free 73696, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 25, idle 189987/s, free 73696, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 28, idle 188912/s, free 65088, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 3/38
    Info:MQTT:mqtt_host empty, not starting mqtt
    Info:MAIN:Time 29, idle 188650/s, free 73704, MQTT 0(2), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 33, idle 198353/s, free 73696, MQTT 0(2), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 37, idle 189849/s, free 73696, MQTT 0(2), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 38, idle 189120/s, free 73704, MQTT 0(2), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 41, idle 186364/s, free 73696, MQTT 0(2), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 42, idle 187401/s, free 73704, MQTT 0(2), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MQTT:mqtt_host empty, not starting mqtt
    Info:MAIN:Time 45, idle 187042/s, free 73696, MQTT 0(3), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 46, idle 193917/s, free 73704, MQTT 0(3), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 49, idle 190406/s, free 73696, MQTT 0(3), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 50, idle 192118/s, free 73704, MQTT 0(3), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:GEN:dhcp=0 ip=XXXXXXX.112 gate=XXXXXXX.1 mask=255.255.255.0 mac=XXXXXXX
    Info:GEN:sta: 1, softap: 0, b/g/n
    Info:GEN:sta:rssi=-27,ssid=XXXXXXX,bssid=XXXXXXX,channel=11,cipher_type:CCMP
    Info:MAIN:Time 53, idle 186731/s, free 73696, MQTT 0(3), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 54, idle 191768/s, free 73704, MQTT 0(3), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 57, idle 187466/s, free 73704, MQTT 0(3), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 58, idle 195886/s, free 73704, MQTT 0(3), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MQTT:mqtt_host empty, not starting mqtt
    Info:MAIN:Time 61, idle 186968/s, free 73696, MQTT 0(4), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 62, idle 202145/s, free 73704, MQTT 0(4), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 65, idle 191772/s, free 73696, MQTT 0(4), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 66, idle 189007/s, free 73704, MQTT 0(4), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 68, idle 195730/s, free 73696, MQTT 0(4), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 70, idle 189679/s, free 73696, MQTT 0(4), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:GEN:dhcp=0 ip=XXXXXXX.112 gate=XXXXXXX.1 mask=255.255.255.0 mac=XXXXXXX
    Info:GEN:sta: 1, softap: 0, b/g/n
    Info:GEN:sta:rssi=-25,ssid=XXXXXXX,bssid=XXXXXXX,channel=11,cipher_type:CCMP
    Info:MAIN:Time 73, idle 184654/s, free 73696, MQTT 0(4), bWifi 1, secondsWithNoPing 3, socks 2/38
    Info:MAIN:Time 74, idle 193679/s, free 73704, MQTT 0(4), bWifi 1, secondsWithNoPing 4, socks 2/38
    Info:MQTT:mqtt_host empty, not starting mqtt
    Info:MAIN:Time 77, idle 190934/s, free 73704, MQTT 0(5), bWifi 1, secondsWithNoPing 2, socks 2/38
    Info:MAIN:Time 78, idle 188365/s, free 73696, MQTT 0(5), bWifi 1, secondsWithNoPing 3, socks 2/38
    Info:MAIN:Time 81, idle 181530/s, free 73704, MQTT 0(5), bWifi 1, secondsWithNoPing 1, socks 2/38
    Info:MAIN:Time 82, idle 189007/s, free 73704, MQTT 0(5), bWifi 1, secondsWithNoPing 2, socks 2/38
    Info:MAIN:Time 85, idle 185055/s, free 73696, MQTT 0(5), bWifi 1, secondsWithNoPing 5, socks 2/38
    ---------------8<-----------------------
  • #10 20934191
    p.kaczmarek2
    Moderator Smart Home
    Oops, it seems a call from frontend was missing. I've checked and fixed that. My self tests missed that because they are injected a bit later in the call chain.

    Added after 14 [seconds]:

    Please update and recheck. Remember to backup your scripts.
    Helpful post? Buy me a coffee.
  • #11 20934694
    tinkertechie
    Level 2  
    Yep, that worked! Awesome.

    I feel bad adding to this, but I may have found another bug. Please forgive me if I have misunderstood documentation, but I couldn't find where this is handled in the source code. I think I found the parser, but I've looked at so many different bits of unfamiliar code today my brain is fzzzzt...

    I've had a bit of a play with trying to get a non-blocking version working, essentially expanding the "sleepy" part of the end of the script I pasted previously (ie: rolling my own waitfor with a way to have a timeout). It makes it a lot easier to handle states that have multiple exit conditions. I have hit a problem though.

    Should this work?:

    addChangeHandler noPingTime < 10 SetChannel 10 3

    What I'm doing is setting up the handler when I know the ping time has become bigger than 10, making sure CH10 is 0, then looping (with delays) until I see CH10 change to 3.

    The technique below works elsewhere when the addChangeHandler relation is ">". I have verified that the ping is greater than ten at the time I set up the handler, but then when the ping time drops below 10 it doesn't fire. Here are two "level 6" log fragments that show the problem. Before this I've had an "addChangeHandler noPingTime > 10 SetChannel 10 2" line that works:

    ---------------8<-----------------------
    Info:MAIN:Time 86, idle 195327/s, free 72360, MQTT 0(5), bWifi 1, secondsWithNoPing 16, socks 2/38
    Info:MAIN:Time 87, idle 187946/s, free 72144, MQTT 0(5), bWifi 1, secondsWithNoPing 17, socks 3/38
    Debug:CMD:cmd [checkwifidown]
    Debug:CMD:cmd [if WiFiState==2 then goto restartnoreboot]
    Debug:CMD:cmd [if 2==$CH10 then goto pinglarge]
    Debug:CMD:cmd [goto pinglarge]
    ExtraDebug:CMD:CMD_GoTo: goto local pinglarge

    *** here I've cleared all the change handlers so I can do a new addChangeHandler - it didn't seem to work without clearing them ***

    Debug:CMD:cmd [addChangeHandler noPingTime < 10 SetChannel 10 3]
    Info:EVENT:CMD_AddChangeHandler: added noPingTime with cmd SetChannel 10 3
    Debug:CMD:cmd [SetChannel 10 0]
    Info:GEN:CHANNEL_Set channel 10 has changed to 0 (flags 0)

    Info:MQTT:Channel has changed! Publishing 0 to channel 10

    Debug:CMD:cmd [delay_s 2]
    ExtraDebug:CMD:CMD_Delay_s: thread will delay 2000 extra ms
    Info:MAIN:Time 88, idle 158342/s, free 72360, MQTT 0(5), bWifi 1, secondsWithNoPing 18, socks 2/38
    Info:MAIN:Time 89, idle 194488/s, free 72360, MQTT 0(5), bWifi 1, secondsWithNoPing 19, socks 2/38
    ---------------8<-----------------------

    then later:

    ---------------8<-----------------------
    Debug:CMD:cmd [delay_s 2]
    ExtraDebug:CMD:CMD_Delay_s: thread will delay 2000 extra ms
    Info:MAIN:Time 383, idle 190952/s, free 72544, MQTT 0(24), bWifi 1, secondsWithNoPing 313, socks 3/38
    Info:MAIN:Time 384, idle 195362/s, free 72760, MQTT 0(24), bWifi 1, secondsWithNoPing 314, socks 2/38
    Debug:CMD:cmd [checkwifidown]
    Debug:CMD:cmd [if WiFiState==2 then goto restartnoreboot]
    Debug:CMD:cmd [if 3==$CH10 then goto moveon3]
    Debug:CMD:cmd [goto sleepy3]
    ExtraDebug:CMD:CMD_GoTo: goto local sleepy3
    Debug:CMD:cmd [delay_s 2]
    ExtraDebug:CMD:CMD_Delay_s: thread will delay 2000 extra ms
    Info:MAIN:Time 385, idle 190233/s, free 72760, MQTT 0(24), bWifi 1, secondsWithNoPing 315, socks 2/38
    Info:MAIN:Time 386, idle 194311/s, free 72760, MQTT 0(24), bWifi 1, secondsWithNoPing 1, socks 2/38
    Debug:CMD:cmd [checkwifidown]
    Debug:CMD:cmd [if WiFiState==2 then goto restartnoreboot]
    Debug:CMD:cmd [if 3==$CH10 then goto moveon3]
    Debug:CMD:cmd [goto sleepy3]
    ExtraDebug:CMD:CMD_GoTo: goto local sleepy3
    Debug:CMD:cmd [delay_s 2]
    ExtraDebug:CMD:CMD_Delay_s: thread will delay 2000 extra ms
    Info:MAIN:Time 387, idle 188226/s, free 64136, MQTT 0(24), bWifi 1, secondsWithNoPing 2, socks 3/38
    Info:MAIN:Time 388, idle 193936/s, free 72760, MQTT 0(24), bWifi 1, secondsWithNoPing 3, socks 2/38
    Debug:CMD:cmd [checkwifidown]
    Debug:CMD:cmd [if WiFiState==2 then goto restartnoreboot]
    Debug:CMD:cmd [if 3==$CH10 then goto moveon3]
    Debug:CMD:cmd [goto sleepy3]
    ExtraDebug:CMD:CMD_GoTo: goto local sleepy3

    ---------------8<-----------------------
  • #12 20934740
    p.kaczmarek2
    Moderator Smart Home
    You are correct. It seems there was an oversight, the change was not called while ping time was reset back to 0. It seems no one ever needed it before. I've pushed a fix, can you check?

    This should work with the new fix:
    
    addChangeHandler noPingTime < 10 SetChannel 10 3
    

    This will be triggered once when pingTime is above 10 and transitions back to 0 (or to 1, due to the handler being called from main and not from IP callback)
    Helpful post? Buy me a coffee.
  • #13 21150977
    tinkertechie
    Level 2  
    >>20934740I lost the need for this, but I believe I tested this change and it was OK. I'll endeavor to do so shortly. I have another question that I'll raise as a new topic. Thanks again for your incredibly prompt replies.

Topic summary

The discussion revolves around the implementation of a ping watchdog feature in a BK7231N-based Tuya smart plug to monitor and reboot unresponsive devices. The user outlines a strategy involving relay control and ping monitoring but encounters delays in the watchdog's activation. Responses highlight the importance of ensuring the device has fully booted before monitoring begins, with suggestions to adjust thresholds for no-ping times and utilize event handlers effectively. The conversation also addresses potential bugs and the need for additional features like timeout for the WaitFor command. The user successfully tests a fix that allows for better handling of ping time changes.
Summary generated by the language model.
ADVERTISEMENT