From 10d4eb78d5c844383b5ec9cdb30dfecebfafb247 Mon Sep 17 00:00:00 2001 From: Adrian Caramaliu Date: Wed, 24 Jan 2024 09:36:47 -0500 Subject: [PATCH] Implement Link Up Interval --- lib/sources/librelinkup.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/sources/librelinkup.js b/lib/sources/librelinkup.js index e7151bd..d533634 100644 --- a/lib/sources/librelinkup.js +++ b/lib/sources/librelinkup.js @@ -100,7 +100,7 @@ function linkUpSource (opts, axios) { }); // return Promise.resolve(auth.data.authTicket); }, - dataFromSesssion (session, last_known) { + dataFromSession (session, last_known) { var two_days_ago = new Date( ).getTime( ) - (2 * 24 * 60 * 60 * 1000); var last_mills = Math.max(two_days_ago, (last_known && last_known.entries) ? last_known.entries.getTime( ) : two_days_ago); var last_glucose_at = new Date(last_mills); @@ -155,12 +155,12 @@ function linkUpSource (opts, axios) { } // var last_glucose_at = new Date(last_known.sgvs.mills); var last_glucose_at = last_known.entries; - var missing = ((new Date( )).getTime( ) - last_glucose_at.getTime( )) / (1000 * 60 * 5) + var missing = ((new Date( )).getTime( ) - last_glucose_at.getTime( )) / (1000 * 60 * opts.linkUpInterval) if (missing > 1 && missing < 3) { console.log("READJUSTING SHOULD MAKE A DIFFERENCE MISSING", missing); } - var next_due = last_glucose_at.getTime( ) + (Math.ceil(missing) * 1000 * 60 * 5); + var next_due = last_glucose_at.getTime( ) + (Math.ceil(missing) * 1000 * 60 * opts.linkUpInterval); var buffer_lag = 18000; // 18 second buffer var jitter = Math.floor(Math.random( ) * 1000 * 18); // 18 second random var align_to = next_due + buffer_lag + jitter; @@ -178,7 +178,7 @@ function linkUpSource (opts, axios) { authorize: impl.sessionFromAuth, // refresh: impl.refreshSession, delays: { - REFRESH_AFTER_SESSSION_DELAY: 3600000 - 600000, + REFRESH_AFTER_SESSION_DELAY: 3600000 - 600000, EXPIRE_SESSION_DELAY: 3600000 } }); @@ -188,7 +188,7 @@ function linkUpSource (opts, axios) { builder.register_loop('LibreLinkUp', { tracker: tracker_for, frame: { - impl: impl.dataFromSesssion, + impl: impl.dataFromSession, align_schedule: impl.align_to_glucose, transform: impl.transformGlucose, backoff: { @@ -200,7 +200,7 @@ function linkUpSource (opts, axios) { maxRetries: 2 }, // expect new data 5 minutes after last success - expected_data_interval_ms: 5 * 60 * 1000, + expected_data_interval_ms: opts.linkUpInterval * 60 * 1000, backoff: { // wait 2.5 minutes * 2^attempt interval_ms: 2.5 * 60 * 1000 @@ -220,6 +220,7 @@ linkUpSource.validate = function validate_inputs (input) { linkUpUsername: input.linkUpUsername, linkUpPassword: input.linkUpPassword, linkUpPatientId: input.linkUpPatientId, + linkUpInterval: input.linkUpInterval || 5, linkUpVersion: input.linkUpVersion || Defaults.Version, linkUpProduct: input.linkUpProduct || Defaults.Product, baseURL