Skip to content

AdhocAdam/CareLink

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation



CareLink for PowerShell

Overview

This PowerShell module is for diabetics looking to retrieve their blood glucose readings from Medtronic Carelink. This is achieved using PowerShell's native Invoke-WebRequest and Invoke-RestMethod's cmdlets.

This module is compatible with PowerShell 5.1 and up. It has been tested and confirmed working with a 770g. Pull Requests are welcome!

Available cmdlets

Cmdlet Purpose
Get-CareLinkToken Retrieves the token currently in use
Set-CareLinkToken Sets the token and expiration date to use in subsequent cmdlets
Confirm-CareLinkToken Used by other functions to confirm your authentication to Carelink is still valid
Get-CareLinkAccount Retrieves information about your account such as login date, account id, and user role
Get-CareLinkProfile Retrieves information about your profile such as username, phone number, email, etc.
Get-CareLinkData Retrieves a detailed object that contains device information, serial number, reservoir levels, last sugar, last 24 hours of sugars, etc.

Getting Started

Since the CareLink data model or command line may not be the most intuitive thing to most users. It's suggested to use either PowerShell ISE (built into Windows) or VSCode to build scripts, debug, and visualize information. For the purposes of demonstration below, examples will take place in VSCode.

Install from the module from the PowerShell Gallery by using the following at a PowerShell prompt

Install-Module -Name CareLink

Authenticate to CareLink

In order to retrieve data, you must first obtain an access token and its expiration date. One means of doing this is:

  1. Open a browser
  2. Log into CareLink
  3. Push F12 to open up Developer Tools and navigate to the Network Tab
  4. Then in CareLink navigate to Data Connect to view your live glucose data
  5. In the list of calls made in the Network tab, filter down for one called "message"

Inspect the Headers to copy out the Token and the Token's Expiration Date. You're looking for values that correspond with "c_token_valid_to" and "auth_tmp_token". Then paste them into the following cmdlet.

Set-CareLinkToken -Expiration "Fri Nov 20 19:17:44 UTC 2023" -Token "c7822ebd1d9bf24609b7..."

Tokens are good for approximatley 40 minutes

Get account/profile details

Once you have set a token, you can execute the following cmdlets to retrieve more information such as your Account and Profile information. You'll ultimately need these to access your sugar data.

$account = Get-CarelinkAccount
$userProfile = Get-CarelinkProfile

Retrieve last sugar, last 24 hours of sugar, device serial number, etc.

Using the $account and $userProfile variables from above. Pass them as values to the Get-CareLinkData cmdlet to retrieve pertinent information. Save the entire object to a variable such as $data to explore.

$data = Get-CarelinkData -CarelinkUserAccount $account -CarelinkUserProfile $userProfile

PowerShell ISE/VSCode exploration

This is where it makes sense to have performed the above commands in one of these two programs as you can just open a new tab to explore the object without continuing to make repeated calls to CareLink. Take the following gif wherein all the commands are executed in a window, then a new window is opened just to explore the $data variable.

loadData01

In VSCode you either use CTRL+N to open a new tab/file, or just head over to File -> New File. Set the language to PowerShell, then hit F5 to run it.

image

If you want to interrogate a specific data point, just add a "." to the end of $data to grab specific data points. For example:

  • $data.lastSG
  • $data.timeFormat

or if you prefer, you can also use the PowerShell pipeline:

$data | Select-Object lastSG, lastSGTrend, activeInsulin, timeFormat, markers

Filter the sugars

There are two relevant sugar datapoints:

  • .lastSG represents the most recent reading, as a single object, updated every 5 minutes from the last reading
  • .sgs represents an array of sugar objects, and will also contain the most recent reading updated every 5 minutes from the last reading

If you were to use $data.sgs, you'd return a list of sugar objects from oldest to most recent. Using PowerShell, we can filter this down such as the last 10 readings, most recent reading, readings with a range, etc.

The last reading

$data.lastSG

The last reading(s)

$data.sgs | Select-Object -Last 1
$data.sgs | Select-Object -Last 10

All readings above (greater than) 160

$data.sgs | Where-Object {$_.sg -gt 160}

Readings between a given range

$data.sgs | Where-Object {($_.sg -ge 90) -and ($_.sg -le 160)}

Disclaimer

This project and subsequent PowerShell Module is not associated, affiliated, endorsed, or supported in any capacity by Medtronic or Microsoft. Use of this module is undertaken entirely at your own risk.