Set Time Frame
Programmatically send downlinks only within individual timeframe, not on weekends, within the week only.
Last updated
Was this helpful?
Was this helpful?
function Encoder(measurements, port) {
// Send the following payload
return [0x00,0xFF,0x00,0xFF];
}function Encoder(measurements, port) {
// WARNING!!! Please note that this is UTC Time!!!
// Please convert to your local timezone!!!
var startTime = '07:00:00'; // 9am CET
var endTime = '16:00:00'; // 6pm CET
var currentDate = new Date()
startDate = new Date(currentDate.getTime());
startDate.setHours(startTime.split(":")[0]);
startDate.setMinutes(startTime.split(":")[1]);
startDate.setSeconds(startTime.split(":")[2]);
endDate = new Date(currentDate.getTime());
endDate.setHours(endTime.split(":")[0]);
endDate.setMinutes(endTime.split(":")[1]);
endDate.setSeconds(endTime.split(":")[2]);
// Check if is valid
var valid = startDate < currentDate && endDate > currentDate
// if the current time lies within the desired timeframe
if (valid) {
// send the actual downlink
return [0x00,0xFF,0x00,0xFF]; // TODO: Replace with your Downlink!
}
// in case it is not valid, do not return anything here
// in order to abort sending a downlink
}var startTime = '07:00:00'; // 9am CET
var endTime = '16:00:00'; // 6pm CETfunction Encoder(measurements, port) {
var startTime = '07:00:00'; // 9am CET
var endTime = '16:00:00'; // 6pm CET
var currentDate = new Date()
startDate = new Date(currentDate.getTime());
startDate.setHours(startTime.split(":")[0]);
startDate.setMinutes(startTime.split(":")[1]);
startDate.setSeconds(startTime.split(":")[2]);
endDate = new Date(currentDate.getTime());
endDate.setHours(endTime.split(":")[0]);
endDate.setMinutes(endTime.split(":")[1]);
endDate.setSeconds(endTime.split(":")[2]);
// is currentDate on weekend?
var weekend = (currentDate.getDay() == 6 || currentDate.getDay() == 0)
var valid = startDate < currentDate &&
endDate > currentDate && !weekend
console.log("Is Valid?: "+valid);
if (valid) {
return [0x00,0xFF,0x00,0xFF];
}
}