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<-----------------------