Skip to content

Commit

Permalink
Merge pull request #69 from timoschlueter/feature/improve-docker-comp…
Browse files Browse the repository at this point in the history
…atibility

Feature/improve docker compatibility
  • Loading branch information
timoschlueter authored Oct 4, 2022
2 parents 5690684 + c624a86 commit 397cea3
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM node:18

LABEL version="1.8.2"
LABEL version="1.9.0"
LABEL description="Script written in JavaScript (Node) that uploads CGM readings from LibreLink Up to Nightscout"

# Create app directory
Expand Down
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ work with at least Freestyle Libre 2 (FGM) and Libre 3 CGM sensors.

The script takes the following environment variables

| Variable | Description | Example | Required |
|-----------------------|------------------------------------------------------------------------------------------------------------------|------------------------------------------|--------|
| LINK_UP_USERNAME | LibreLink Up Login Email | [email protected] | X |
| LINK_UP_PASSWORD | LibreLink Up Login Password | mypassword | X |
| LINK_UP_CONNECTION | LibreLink Up Patient-ID. Can be received from the console output if multiple connections are available. | 123456abc-abcd-efgh-7891def | |
| LINK_UP_TIME_INTERVAL | The time interval of requesting values from libre link up | 5 | |
| LINK_UP_REGION | Your region. Used to determine the correct LibreLinkUp service (Possible values: US, EU, DE, FR, JP, AP, AU, AE) | EU | |
| NIGHTSCOUT_URL | Hostname of the Nightscout instance (without https://) | nightscout.yourdomain.com | X |
| NIGHTSCOUT_API_TOKEN | SHA1 Hash of Nightscout access token | 162f14de46149447c3338a8286223de407e3b2fa | X |
| LOG_LEVEL | The setting of verbosity for logging, should be one of info or debug | info | X |
| Variable | Description | Example | Required |
|--------------------------|------------------------------------------------------------------------------------------------------------------|------------------------------------------|----------|
| LINK_UP_USERNAME | LibreLink Up Login Email | [email protected] | X |
| LINK_UP_PASSWORD | LibreLink Up Login Password | mypassword | X |
| LINK_UP_CONNECTION | LibreLink Up Patient-ID. Can be received from the console output if multiple connections are available. | 123456abc-abcd-efgh-7891def | |
| LINK_UP_TIME_INTERVAL | The time interval of requesting values from libre link up | 5 | |
| LINK_UP_REGION | Your region. Used to determine the correct LibreLinkUp service (Possible values: US, EU, DE, FR, JP, AP, AU, AE) | EU | |
| NIGHTSCOUT_URL | Hostname of the Nightscout instance (without https://) | nightscout.yourdomain.com | X |
| NIGHTSCOUT_API_TOKEN | SHA1 Hash of Nightscout access token | 162f14de46149447c3338a8286223de407e3b2fa | X |
| NIGHTSCOUT_DISABLE_HTTPS | Disables the HTTPS requirement for Nightscout URLs | true | |
| LOG_LEVEL | The setting of verbosity for logging, should be one of info or debug | info | |
| SINGLE_SHOT | Disables the scheduler and runs the script just once | true | |

## Usage

Expand Down
12 changes: 11 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,20 @@
"value": "",
"required": true
},
"NIGHTSCOUT_DISABLE_HTTPS": {
"description": "Disables the HTTPS requirement for Nightscout URLs",
"value": "",
"required": false
},
"LOG_LEVEL": {
"description": "The log-level to use.",
"value": "info",
"required": true
"required": false
},
"SINGLE_SHOT": {
"description": "Disables the scheduler and runs the script just once",
"value": "",
"required": false
}
}
}
63 changes: 43 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,16 @@ function getLibreLinkUpUrl(region) {
/**
* NightScout API
*/
const NIGHT_SCOUT_URL = process.env.NIGHTSCOUT_URL;
const NIGHT_SCOUT_API_TOKEN = process.env.NIGHTSCOUT_API_TOKEN;
const NIGHTSCOUT_URL = process.env.NIGHTSCOUT_URL;
const NIGHTSCOUT_API_TOKEN = process.env.NIGHTSCOUT_API_TOKEN;
const NIGHTSCOUT_DISABLE_HTTPS = process.env.NIGHTSCOUT_DISABLE_HTTPS || false;

function getNightscoutUrl() {
if (NIGHTSCOUT_DISABLE_HTTPS === "true") {
return "http://" + NIGHTSCOUT_URL;
}
return "https://" + NIGHTSCOUT_URL;
}

/**
* last known authTicket
Expand All @@ -82,14 +90,18 @@ const libreLinkUpHttpHeaders = {
}

const nightScoutHttpHeaders = {
"api-secret": NIGHT_SCOUT_API_TOKEN,
"api-secret": NIGHTSCOUT_API_TOKEN,
"User-Agent": USER_AGENT,
"Content-Type": "application/json",
}

const schedule = "*/" + (process.env.LINK_UP_TIME_INTERVAL || 5) + " * * * *";
logger.info("Starting cron schedule: " + schedule)
cron.schedule(schedule, () => {main();}, {});
if (process.env.SINGLE_SHOT === "true") {
main().then();
} else {
const schedule = "*/" + (process.env.LINK_UP_TIME_INTERVAL || 5) + " * * * *";
logger.info("Starting cron schedule: " + schedule)
cron.schedule(schedule, () => { main().then() }, {});
}

async function main() {
if (hasValidAuthentication() === false) {
Expand Down Expand Up @@ -139,8 +151,6 @@ async function getGlucoseMeasurements() {
headers: getLluAuthHeaders()
});

logger.info("Received blood glucose measurement items");

await uploadToNightScout(response.data.data);
} catch (error) {
logger.error("Error getting glucose measurements", error);
Expand Down Expand Up @@ -194,7 +204,7 @@ async function getLibreLinkUpConnection() {
}

async function lastEntryDate() {
const url = "https://" + NIGHT_SCOUT_URL + "/api/v1/entries?count=1"
const url = getNightscoutUrl() + "/api/v1/entries?count=1"
const response = await axios.get(
url,
{
Expand Down Expand Up @@ -239,18 +249,31 @@ async function uploadToNightScout(measurementData) {
}
});

try {
const url = "https://" + NIGHT_SCOUT_URL + "/api/v1/entries"
await axios.post(
url,
formattedMeasurements,
if (formattedMeasurements.length > 0)
{
logger.info("Trying to upload " + formattedMeasurements.length + " glucose measurement items to Nightscout");
try
{
const url = getNightscoutUrl() + "/api/v1/entries"
const response = await axios.post(
url,
formattedMeasurements,
{
headers: nightScoutHttpHeaders
});
if (response.status !== 200)
{
headers: nightScoutHttpHeaders
});

logger.info("Upload of " + formattedMeasurements.length + " measurements to NightScout succeeded");
} catch (error) {
logger.error("Upload to NightScout failed ", error);
logger.error("Upload to NightScout failed ", response.statusText);
} else
{
logger.info("Upload of " + formattedMeasurements.length + " measurements to Nightscout succeeded");
}
} catch (error)
{
logger.error("Upload to NightScout failed ", error);
}
} else {
logger.info("No new measurements to upload");
}
}

Expand Down
15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nightscout-librelink-up",
"version": "1.8.2",
"version": "1.9.0",
"description": "Script written in JavaScript (Node) that uploads CGM readings from LibreLink Up to Nightscout",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -33,6 +33,6 @@
"dependencies": {
"axios": "^0.27.2",
"node-cron": "3.0.2",
"winston": "^3.8.1"
"winston": "^3.8.2"
}
}

0 comments on commit 397cea3

Please sign in to comment.