If I have to restart my modem often like a caveman, I'll at least automate it.
Years ago I would have pitied the soul which had to restart their Internet modem often, Now I'm in the situation where the ISP seems to have not heard about network reliability and so my modem hangs at least once per day.
My modem is completely managed by the ISP and so there are no useful options for me to fix the issue. Even the scheduled reboot doesn't work if the modem hangs before the scheduled time. I use a separate OpenWRT router for internal networking and security.
It became clear that I have to automate the power cycling of the modem and for that I used Node RED in Home Assistant, smart plug which allows me to control locally and Gotify to inform me when this all happens.
I found a fellow high-tech neanderthal on reddit doing the same, taking some inspiration from them I created my own work of art -
Sorry about the spaghetti code, I'm a time-constrained person and so I promise to improve it incrementally.
It works like this,
modem_reset_timestamp
is null/empty or more than an a hour old then forward the fail counter value else do nothing (to avoid endless modem restart during ISP downtime).// Ping Evaluation
var MsgFail = {Payload: "PING FAIL"};
var MsgHighPing = {Payload: "HIGH PING"};
var MsgNormalPing = {reset: "true"};
// if ping fails, message goes out first input
// if ping is slow, message goes out second
// if ping is normal, message goes out third
if (msg.payload == false){
return [MsgFail, null];
} else if (msg.payload > 150) {
return [null, MsgHighPing];
} else if (msg.payload < 150) {
return [MsgNormalPing, MsgNormalPing];
}
// reset_timestamp_eval
const modem_reset_timestamp = flow.get('modem_reset_timestamp');
function isMoreThanAnHourOld(modemResetTimestamp) {
const ONE*HOUR = 60 * 60 \_ 1000; // 1 hour in milliseconds
const currentTimeInMilliseconds = new Date().getTime(); // Current time in milliseconds
// Calculate the difference between the modem reset timestamp and the current time
const diff = currentTimeInMilliseconds - modemResetTimestamp;
// Check if the difference is greater than one hour
return diff > ONE_HOUR;
}
if (modem_reset_timestamp == undefined || modem_reset_timestamp == null){
node.warn('The timestamp is null or undefined.');
return [{ count: msg.count }, null];
}
else if (isMoreThanAnHourOld(modem_reset_timestamp)) {
node.warn('The timestamp is more than an hour old.');
return [{ count: msg.count }, null];
} else {
node.warn('The timestamp is not more than an hour old.');
return [null, null];
}
And this works spectacularly,
So well that it doesn't hurt as much as it used to during the countless hours setting up this automation instead of coordinating with other customers to force the ISP to get its act together.
I strive to write low frequency, High quality content on Health, Product Development, Programming, Software Engineering, DIY, Security, Philosophy and other interests. If you would like to receive them in your email inbox then please consider subscribing to my Newsletter.