Last active
April 12, 2024 10:07
-
-
Save muety/dd3adc09f8c5b233eb37ba3c69873861 to your computer and use it in GitHub Desktop.
Shelly 2. Gen device script to repeatedly check for WiFi status and reboot the device if disconnected for long enough
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reboot after 5 minutes of disconnect | |
let wait_sec = 30; | |
let retries = 10; | |
let c = 0; | |
let timer = Timer.set(wait_sec * 1000, true, function () { | |
Shelly.call('WiFi.GetStatus', null, function (result, error_code) { | |
if (result.status !== 'got ip') { | |
if (c++ < retries) { | |
print('wifi not connected, waiting another', (retries - c) * wait_sec, 'seconds until reboot'); | |
} else { | |
print('rebooting to reconnect to wifi'); | |
Shelly.call('Shelly.reboot', null, function() {}); | |
} | |
} else { | |
c = 0; | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment