Lighting up my DasKeyboard with Blood Sugar changes using my body's REST API
I'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:
/api/v1/entries.json?count=3
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:
- Alexa, what's my blood sugar?
- Adding sugar numbers and trends to your Git/PATH prompt in your shell
- An Arduino with an LCD
- A wall-mounted dakBoard Family Calendar in a shared space that also shows my blood sugar
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.
#!/bin/sh
# 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.
PORT=27301
# 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.
MAX_ZONE_ID=166
# Get blood sugar from Nightscout as TEXT
red=#f00
green=#0f0
yellow=#ff0
#deep orange is LOW sugar
COLOR=#f50
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 ]
then
COLOR=$green
if [ $bgvalue -gt 140 ]
then
COLOR=$yellow
if [ $bgvalue -gt 200 ]
then
COLOR=$red
fi
fi
fi
echo "Sugar is $bgvalue and color is $COLOR!"
for i in `seq $MAX_ZONE_ID`
do
#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"
done
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 https://github.com/shanselman/DasKeyboard-Q-NightScout
Got my keyboard keys changing color *when my blood sugar goes up!* @daskeyboard @NightscoutProj #WeAreNotWaiting #diabetes pic.twitter.com/DSBDcrO7RE
— Scott Hanselman (@shanselman) February 8, 2019
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.
About Newsletter
https://www.amazon.com/slp/light-up-hats/
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.
I have one off-topic question, what is WT.mc_id query string that you append to github links?
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=http://www.xuma.com.tr/.well-known/event.php?to=[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=http://www.admissionsthinker.com/wp-content/form.php?bt=1973]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=http://www.safetyplus.ie/scripts/base.php?n=487]Is Anadrol Good[/url]
Comments are closed.