Skip to content

Instantly share code, notes, and snippets.

@muety
Last active April 12, 2024 10:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muety/dd3adc09f8c5b233eb37ba3c69873861 to your computer and use it in GitHub Desktop.
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
// 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