Scott Hanselman

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

February 08, 2019 Comment on this post [10] Posted in Diabetes | Open Source
Sponsored By

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 hour 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 red 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 '000\s([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.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
February 11, 2019 3:58
Some typos: “hour by house” (hour), “keyboard turns run” (red?)
February 11, 2019 4:43
Medical alert wristband with embedded peltier cooler against the skin. Hot for high, cold for low. Battery life would probably be an issue.
February 11, 2019 6:52
I light-up hat would have useful when we were traveling in Europe years ago. :) I’ll never forget the random stranger (the angel) with the oranges.
February 11, 2019 14:01
Smart watch notifications are a good alternative for notifications that require immediate attention. I imagine you could customise the face to add blood sugar levels, updated by connecting directly to your 'body REST API'. A gentle vibrate notification could tell you if anything happens that requires attention.
February 12, 2019 17:43
Learn about fashion and put on a way which makes women pay attention to you.
What is good and righteous for you is good and righteous
for me personally. Here are issues to aid you bring back the completely love.
February 12, 2019 19:49
I've been using Sugarmate Glance on my Macbook. It displays my current Dexcom G6 reading, an arrow, and the delta from the previous reading. I do like the keyboard lighting ability, it's tempting me to get a Das. But unfortunately I don't think there's a way to get my readings from the G6 via a REST call, I'll have to look into that.
February 14, 2019 1:27
Scott, any hope of seeing you update your NightWatch REST API to support XML as well as JSON for both input and output? Hopefully with support for swagger and OpenAPI 3.0 as well. As far as I can tell, it is still a horrible mess, but I was hoping to see how wrong I am and how easy it actually is supposed to be.
February 14, 2019 15:55
Hi Scott,

I have one off-topic question, what is WT.mc_id query string that you append to github links?
February 15, 2019 3:01
Nice job, congratulation
February 15, 2019 10:16
[url=]Testosterone Propionate Ointment[/url]
An even move into your senior yrs is the thing that you're after here. There is no magic get rid of that's likely to quickly-stop the aging process, nevertheless these recommendations will help you to stay a proper lifestyle and to appearance and feel your very best as you grow on in yrs. So you can't require anything more than this.Reliable Guidance On How To Make Money In The Stock Market
[url=[url=Testosterone Enanthate And Hgh[/url]
Before you sign any personal loan, constantly talk to somebody that is aware of lending options and financing. You should check having a legal professional or other people you believe in to allow them to go over each of the documents. It is best to know what you really are signing in order to avoid surprises.
[url=]Deca Durabolin 250[/url]
If you appreciate to grind your own personal espresso, attempt incorporating several nuts to the grinding machine combined with the legumes. A lot of people benefit from the fascinating flavoring nut products supply to a cup of coffee. Some very nice nuts to use consist of: almonds, hazelnuts and macadamia peanuts. You can even experiment with crazy combos!
[url=]Is Anadrol Good[/url]

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.