Hello,
i am trying to do schedule firmware upgrade but setting time not working,
const now = Date.now();
const softwareVersion = declare(“Device.DeviceInfo.SoftwareVersion”, { value: now }).value[0];
const productClass = declare(“DeviceID.ProductClass”, { value: now }).value[0];
commit();
const futureTime = randomFutureTime(); // Random future time is defined here
const readableNow = new Date(now).toString();
const readableFutureTime = new Date(futureTime).toString();
// Logging
log(Script: now - Current Timestamp: ${now}
);
log(Script: now - Random Future Timestamp: ${futureTime}
);
log(Script: now - Readable Current Time: ${readableNow}
);
log(Script: now - Readable Future Time: ${readableFutureTime}
);
if (softwareVersion !== “XXXXXX v2.1 b366”) {
switch (productClass) {
case “XXXXXXXXXX”:
log(“XXXXXXXXXX - Upgrading to XXXXX v2.1 b366 firmware”);
configureFirmwareUpgrade(“file.bin”);
break;
}
}
function configureFirmwareUpgrade(fileName) {
declare(“Downloads.[FileType:1 Firmware Upgrade Image]”, { path: 1 }, { path: 1 });
declare(“Downloads.[FileType:1 Firmware Upgrade Image].FileName”, { value: 1 }, { value: fileName });
declare(“Downloads.[FileType:1 Firmware Upgrade Image].Download”, { value: 1 }, { value: futureTime });
}
function randomFutureTime() {
const now = Date.now(); // Current timestamp
const minMinutes = 1; // Minimum 1 minute
const maxMinutes = 5; // Maximum 5 minutes
const randomMinutes = Math.floor(Math.random() * (maxMinutes - minMinutes + 1)) + minMinutes; // Random minutes
const randomMillis = randomMinutes * 60 * 1000; // Convert minutes to milliseconds
return now + randomMillis; // Add random duration to current time
}