Lighting up my DasKeyboard with Blood Sugar changes using my body’s REST API

imageI’ve long blogged about the intersection of diabetes and technology. From the sad state of diabetes tech in 2012 to its recent promising resurgence, it’s clear that we are not waiting.

If you’re a Type 1 Diabetic using a CGM – a continuous glucose meter – you’ll want to set up Nightscout so you can have a REST API for your sugar. The CGM checks my blood sugar every 5 minutes, it hops via BLE over to my phone and then to the cloud. You’ll want your sugars stored in cloud storage that YOU control. CGM vendors have their own cloud, but we can easily bridge over to a MongoDB database.

I run Nightscout in Azure and my body has a REST API. I can do an HTTP GET like this:


and get this

_id: "5c6066d477b2a69a0a7810e5",
sgv: 143,
date: 1549821626000,
dateString: "2019-02-10T18:00:26.000Z",
trend: 4,
direction: "Flat",
device: "share2",
type: "sgv"
_id: "5c6065a877b2a69a0a7801ce",
sgv: 134,
date: 1549821326000,
dateString: "2019-02-10T17:55:26.000Z",
trend: 4,
direction: "Flat",
device: "share2",
type: "sgv"
_id: "5c60647b77b2a69a0a77f381",
sgv: 130,
date: 1549821026000,
dateString: "2019-02-10T17:50:26.000Z",
trend: 4,
direction: "Flat",
device: "share2",
type: "sgv"

I can change the URL from a .json to a .txt and get this

2019-02-10T18:00:26.000Z    1549821626000    143    Flat    
2019-02-10T17:55:26.000Z 1549821326000 134 Flat
2019-02-10T17:50:26.000Z 1549821026000 130 Flat

The “flat” value at the end is part of an enum that can give me a generalized trend value. Diabetics need to manage our sugars at the least hour by house and sometimes minute by minute. As such it’s super important that we have “glanceable displays.” That means anything at all that gives me a sense (a sixth sense, if you will) of how I’m doing.

That might be:

I got a Das Keyboard 5Q recently – I first blogged about Das Keyboard in 2006! and noted that it’s got it’s own local REST API. I’m working on using their Das Keyboard Q software’s Applet API to light up just the top row of keys in response to my blood sugar changing. It’ll use their Node packages and JavaScript and run in the context of their software.

However, since the keyboard has a localhost REST API and so does my blood sugar, I busted out this silly little shell script. Add a cron job and my keyboard can turn from orange (low), to green, yellow, red (high) as my sugar changes. That provides a nice ambient notifier of how my sugars are doing. Someone on Twitter said “who looks at their keyboard?” I mean, OK, that’s just silly. If my entire keyboard turns run I will notice it. Again, ambient. I could certainly add an alert and make a klaxon go off if you’d like.

# This script colorize all LEDs of a 5Q keyboard
# by sending JSON signals to the Q desktop public API.
# based on Blood Sugar values from Nightscout
set -e # quit on first error.

# Colorize the 5Q keyboard
PID="DK5QPID" # product ID

# Zone are LED groups. There are less than 166 zones on a 5Q.
# This should cover the whole device.

# Get blood sugar from Nightscout as TEXT
#deep orange is LOW sugar
bgvalue=$(curl -s https://MYSITE/api/v1/entries.txt?count=1 | grep -Eo '000s([0-9]{1,3})+s' | cut -f 2)
if [ $bgvalue -gt 80 ]
if [ $bgvalue -gt 140 ]
if [ $bgvalue -gt 200 ]

echo "Sugar is $bgvalue and color is $COLOR!"

for i in `seq $MAX_ZONE_ID`
#echo "Sending signal to zoneId: $i"
# important NOTE: if field "name" and "message" are empty then the signal is
# only displayed on the devices LEDs, not in the signal center
curl -s -S --output /dev/null -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
"name": "Nightscout",
"id": "'$i'",
"message": "Blood sugar is '$bgvalue'",
"pid": "'$PID'",
"zoneId": "'"$i"'",
"color": "'$COLOR'",
"effect": "SET_COLOR"

}' "http://localhost:$PORT/api/1.0/signals"

echo "nDone.n"

This local keyboard API is meant to send a signal to a single zone or key, so it’s hacky of me (and them, really) to make 100+ REST calls to color the whole keyboard. But, it’s a localhost call and it’s not that spendy. This will go away when I move to their new API. Here’s a video of it working.

You can also hit the volume button on the keyboard an any “signaled” (lit up) key and get a popup with the actual blood sugar value (that’s ‘message’ in the second curl command above). Again, this is a hack but I’m going to make it a formal applet you can just install from the store. If you want to help (I’m slow) head to the code here

What are some other good ideas for ambient sugar alerts? An LCD strip around the monitor (bias lighting)? A Phillips Hue smart light?

Consider also that you could use the glanceable display idea for pulse, anxiety, blood pressure – anything in your body you could hook up to in real- or near-realtime.

Sponsor: Get the latest JetBrains Rider with Code Vision, Rename Project refactoring, and the Assembly Explorer. Improved support for C#, VB.NET, F#, TypeScript, and Angular is all included.

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *