Libre 2 To Nightscout

Updated: 2022/11/15

I’m a user of Abbott’s Freestyle Libre 2 continuous glucose monitor. It’s not amazing, but it’s very much cheaper than it’s main competition, Dexcom, and American insurance companies are tightening down qualification for CGM coverage. Abbott doesn’t really like sharing data from it’s Libre ecosystem so there’s not really easy ways to get your data into other apps or services to do whatever you want.

However, there’s a way to get it into a Nightscout instance. Here, I will provide what I think is the easiest way to get this working, and best of all, for free.

This will work for Libre 2 and Libre 3 users. If you are a Dexcom user, you can skip the Libre specific parts of this to get up and running.

Northflank

This will be made possible using a service called Northflank . Unlike other methods, we will not need Github nor MongoDB Atlas. Everything will be contained within Northflank.

Northflank has a free offering, where you are allowed one free project per account. This free project allows 2 services and an addon, which is what we need to accomplish this. The two services will be Nightscout and the LibreLinkUp uploader, and the addon we will use is MongoDB. The MongoDB offering provides a 4GB SSD backing it, which will provide more than enough storage for our needs by a large margin.

Please keep in mind this type of deployment is meant for development and is missing key functionality to ensure it stays online and stable. While it’s likely you’ll never have a problem with it, you should expect that, at some point, you will. If you want more resiliency, that comes at a cost. Accomplishing that will be out of scope of this article. At the very least, the free offering allows backup of your data on a schedule.

While we will be creating a free project, you still need to provide payment information to Northflank.

Go to their website and create a new account. Verify your email. Choose the theme you like and click Next. We don’t need to link a Git account, so click Skip for now. This will, then, prompt you to create a new project. Click Create free project. Next, give it a name and choose a color (this doesn’t matter overall, so pick your favorite). Select the region that works best for you.

You are now ready to get started deploying stuff.

Create MongoDB Addon

First, let’s deploy MongoDB:

  • At the top right, click Create new.
  • Click Addon
  • Click MongoDB
  • Give it a name (I use nightscout-mongodb)
  • Scroll all the way down and click Create addon

For safety, let’s enable backups:

  • On the left, click Backup schedules
  • Click Add schedule
  • Change Backup type to “Dump”
  • Change Repeat to Weekly
  • At the bottom, click Save 1 change

The backup type of Dump gives us the flexibility to easily download one of these backups to use somewhere else if we decide not to use Northflank anymore. For larger databases, this is not a preferred backup type, but we should never get large enough for this to matter.

A weekly repeat frequency should be adequate for our needs. If you would prefer to take daily backups, you can use that instead. Hourly backups would be pretty pointless.

MongoDB is now ready to use.

Create Nightscout Service

Now, let’s deploy Nightscout:

  • At the top right, click Create new
  • Click Service
  • At the block that says I want to…, click Deploy a Docker image
  • Enter “nightscout” as the name
  • In the Deployment block, click External Image
  • In the Image path field, paste: nightscout/cgm-remote-monitor:latest
  • Wait for verification
  • In the Environment variables block, click Runtime variables to expand it

There are 19 variables we will be adding. Go ahead and click Add variable 18 times to get 19 sets of fields ready to go. Here are the keys:

  • ENABLE - careportal basal dbsize rawbg iob maker cob bwp cage iage sage boluscalc pushover treatmentnotify loop pump profile food openaps bage alexa override speech cors
  • SHOW - dbsize
  • BG_HIGH - 250 or whatever you want the max value to be
  • BG_LOW - 55 or whatever you want your min value to be
  • BG_TARGET_TOP - 180 or whatever target range high you want
  • BG_TARGET_BOTTOM - 70 or whatever target range low you want
  • ALARM_URGENT_HIGH - off
  • ALARM_URGENT_LOW - off
  • ALARM_HIGH - off
  • ALARM_LOW - off
  • ALARM_TIMEAGO_WARN - off
  • ALARM_TIMEAGO_URGENT - off
  • NIGHT_MODE - off
  • THEME - colors
  • AUTH_DEFAULT_ROLES - denied - This is required to secure access
  • DBSIZE_MAX - 3000 - MongoDB has 4GB of storage, but we’re limiting it to allow metadata space as well
  • DBSIZE_WARN_PERCENTAGE - 70
  • DBSIZE_URGENT_PERCENTAGE - 80
  • INSECURE_USE_HTTP - true

A note on alarms: I don’t use alarms in Nightscout. I use Nightscout so other apps can access my data and those apps and tools have their own sets of alarms. Set these to on if you would like Nightscout to alarm.

Scroll all the way down and click Create service.

We are now done creating the service, but it will not, yet, be functional.

Create Secrets

We will be storing some of our environment variables in an area called Secrets. We’ll start with creating the Secrets group from the MongoDB Addon.

  • On the left, click Addons
  • Click the mongodb deployment
  • On the left, click connection details
  • On the right, click link to seret groups
  • Click create a new secret group
  • Name the secret group, I used Nightscout
  • In the Secrets block, click Add variable 4 times
  • Add the following:
    • LINK_UP_USERNAME - Your LibreLinkUp username
    • LINK_UP_PASSWORD - Your LibreLinkUp password
    • API_SECRET - A password of your choosing
    • NIGHTSCOUT_API_TOKEN - Leave empty for now
  • Scroll down to Linked addons
  • Click show addons
  • At the right, click configure
  • Click MONGO_SRV
  • Click the + next to aliases
  • Enter MONGODB_URI
  • Scroll to the bottom of the page
  • Click create secret group

Now that the group is created, we need to restart Nightscout.

  • On the left, click Services
  • On the far right of the Nightscout service is a button to restart called Rollout restart - click it
  • Wait for restart to complete

The service will take a small amount of time to start, so loading the page may not work initially. However, click on the Nightscout service entry and scroll down to the block called Ports. There is a DNS column in this block, which contains what your Nightscout URL will be. It’s rather ugly and not easy to remember. I recommend saving it somewhere. To the left of the URL is a copy button. To the right is a link to open the page. Click the link to open the page.

If you reach a page that has a line of text ending in “delayed connect error: 111”, refresh the page until Nightscout loads.

Your first time loading Nightscout will require authentication. Enter the value you used for API_SECRET. If you don’t want it prompting for this every time you load a page, check the checkbox for Remember this device. Click Authenticate.

Still with the first time loading Nightscout, you will be prompted to create a profile. Click ok on the popups until it loads the profile editor. Scroll down and click Save. So long as you had Nightscout remember your device, you should not need to re-authenticate.

At the top right, you should see Status: success. Click the X next to it.

You should now be at the main Nightscout page with no data.

Create Nightscout API Tokens

For the LibreLinkUp uploader to work with Nightscout with the current security settings, a token needs to be created.

  • In Nightscout, click the 3 bars at the top right
  • Click Admin Tools
  • Under the Subjects block, click Add new Subject
  • Give it a name (I use librelinkup)
  • In the role field, enter admin
  • Click Save

A new token will be generated. Save this for later. Follow the same steps to create a “readable” token for your follower apps (ie: sugarmate, shuggah, xdrip+, etc). Name it something interesting, but give it “readable” role instead of “admin”.

You can create a token per app, or just create a single token for all apps.

Once done, you can close this.

Create LibreLinkUp Uploader Service

Head back to the Northflank page so that we can create the service responsible for getting data from LibreLinkUp into Nightscout.

  • At the top right, click Create new
  • Click Service
  • Give it a name (I use librelinkup)
  • In the Deployment block, click External Image
  • In the Image path field, paste: timoschlueter/nightscout-librelink-up:latest
  • Wait for verification
  • In the Environment variables block, click Runtime variables to expand it
    • LINK_UP_TIME_INTERVAL - 5
    • LINK_UP_REGION - US
    • NIGHTSCOUT_URL - nightscout:1337
    • LOG_LEVEL - info
    • NIGHTSCOUT_DISABLE_HTTPS - true
  • Scroll all the way down
  • Click creat service
  • On the left, click Secrets
  • Click the secrets group created earlier.
  • At the right, click edit
  • For the NIGHTSCOUT_API_TOKEN, paste in the empty field the token created earlier
  • Click update configuration
  • On the left, click Services
  • On the far right of the librelinkup uploader service, click the button to rollout restart
  • Click Restart service

A 5 minute time interval is perfectly fine for Libre 2. If you are using a Libre 3, you can reduce this to 1 minute.

You should use the region that is correct for you. I don’t know all of the supported regions for the Libre systems.

It will take some time for the service to start. If all goes well, in about 5-10 minutes, you should see data points start appearing in Nightscout.