Skip to content

Instantly share code, notes, and snippets.

@giu1io
Created December 18, 2022 12:04
Show Gist options
  • Save giu1io/f552c65f3f063e819f4c842ff66ac217 to your computer and use it in GitHub Desktop.
Save giu1io/f552c65f3f063e819f4c842ff66ac217 to your computer and use it in GitHub Desktop.
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