Created
December 18, 2022 12:04
-
-
Save giu1io/f552c65f3f063e819f4c842ff66ac217 to your computer and use it in GitHub Desktop.
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
let shellyId = 'shellyplus1-xxxxxxxx'; | |
let messageId = 0; | |
let ackId = null; | |
function messageIdGetter() { | |
if(messageId > 99) { | |
messageId = 0 | |
} | |
messageId++ | |
return messageId | |
} | |
function sendMessage() { | |
MQTT.publish('shellies/' + shellyId + '/keep_alive/id', JSON.stringify(messageIdGetter())) | |
Timer.set(2000, false, checkAck) | |
} | |
function checkAck() { | |
if(messageId !== ackId) { | |
print('Has to reboot') | |
Shelly.call('Shelly.Reboot', '', function(result, error_code, error_message) { | |
if(error_code !== 0) { | |
print(error_message) | |
} | |
else { | |
print('Rebooting Now') | |
} | |
}) | |
} | |
} | |
MQTT.subscribe('shellies/' + shellyId + '/keep_alive/ack', function(topic, message) { | |
ackId = JSON.parse(message) | |
}) | |
Timer.set(60 * 1000, true, sendMessage, {}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment