In my use case, I must sync the device in 9.30, 14.30, 21.30 and 02.30 every day. So 5 h, 7h, 5h, 7h.
Can you please take a look at my code I have modeled it after one of the default apps I found on your server. Is everything ok with it, is this the simplest way to do this or is there a better way?
Is it interfering with the ‘stolen’ mode the way it is written?
var TRIGGER_TIME9 = {
hour: 15, // 0-23
minute: 30 // 0-59
};
var TRIGGER_TIME14 = {
hour: 15, // 0-23
minute: 33 // 0-59
};
var TRIGGER_TIME19 = {
hour: 15, // 0-23
minute: 35 // 0-59
};
var TRIGGER_TIME0 = {
hour: 15, // 0-23
minute: 39 // 0-59
};
function runTaskAndScheduleNext9() {
runTask( location.startUpdates((position) => {
cloud.enqueue('position-change', { lat: position.lat, long: position.long});
}, {minInterval: 10, minDistance: 10.2, timeout: 120}));
scheduleNextTask(timers.at(TRIGGER_TIME14, runTaskAndScheduleNext14));
}
timers.at(TRIGGER_TIME9, runTaskAndScheduleNext9);
function runTaskAndScheduleNext14() {
runTask( location.startUpdates((position) => {
cloud.enqueue('position-change', { lat: position.lat, long: position.long});
}, {minInterval: 10, minDistance: 10.2, timeout: 120}));
scheduleNextTask(timers.at(TRIGGER_TIME19, runTaskAndScheduleNext19));
}
timers.at(TRIGGER_TIME14, runTaskAndScheduleNext14);
function runTaskAndScheduleNext19() {
runTask( location.startUpdates((position) => {
cloud.enqueue('position-change', { lat: position.lat, long: position.long});
}, {minInterval: 10, minDistance: 10.2, timeout: 120}));
scheduleNextTask(timers.at(TRIGGER_TIME0, runTaskAndScheduleNext0));
}
timers.at(TRIGGER_TIME19, runTaskAndScheduleNext19);
function runTaskAndScheduleNext0() {
runTask( location.startUpdates((position) => {
cloud.enqueue('position-change', { lat: position.lat, long: position.long});
}, {minInterval: 10, minDistance: 10.2, timeout: 120}));
scheduleNextTask(timers.at(TRIGGER_TIME9, runTaskAndScheduleNext9));
}
timers.at(TRIGGER_TIME0, runTaskAndScheduleNext0);
// updating location every 4 hours conserving battery
location.startUpdates((position) => {
cloud.enqueue('position-change', { lat: position.lat, long: position.long});
}, { minInterval: 120, minDistance: 0, timeout: 0});
// button turns alarm mode
io.press(() => {
sync.setSyncPeriod(300);
sync.now();
print('ALARM MODE');
location.startUpdates((position) => {
cloud.enqueue('position-change', { lat: position.lat, long: position.long});
}, { minInterval: 0, minDistance: 1, timeout: 0});
print('cordinates are send to cloud');
});
// alarm mode activated from distance
cloud.onReceive( msg => {
if(msg.type === 'stolen') {
sync.setSyncPeriod(msg.payload.sync_period);}
}
);