使用我身体的REST API用血糖变化点亮DasKeyboard

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.

我长期以来一直在写有关糖尿病与技术的交集的博客。 从2012年令人沮丧的糖尿病技术发展最近令人鼓舞的复苏,很明显我们没有等待

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.

如果您是使用CGM(连续血糖仪)的1型糖尿病患者,则需要设置Nightscout,以便可以为糖使用REST API。 CGM每5分钟检查一次我的血糖,它通过BLE跳到我的手机上,然后跳到云端。 您需要将糖存储在您控制的云存储中。 CGM供应商拥有自己的云,但是我们可以轻松地接到MongoDB数据库。

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

我在Azure中运行Nightscout,并且我的身体具有REST API。 我可以这样执行HTTP GET:

/api/v1/entries.json?count=3

/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

我可以将URL从.json更改为.txt并获取

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.

我最近得到了Das Keyboard 5Q-我在2006年首次写了有关Das Keyboard的博客! 并指出它拥有自己的本地REST API。 我正在使用他们的Das Keyboard Q软件的Applet API来仅点亮第一行按键,以响应我的血糖变化。 它将使用其Node包和JavaScript并在其软件的上下文中运行

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.

但是,由于键盘具有本地主机REST API,血糖也是如此,因此我删除了这个愚蠢的小shell脚本。 添加一个cron作业,随着糖的变化,我的键盘可以从橙色(低)变成绿色,黄色,红色(高)。 这样可以很好地通知我的糖的状况。 Twitter上的某人说:“谁在看他们的键盘?” 我的意思是,好的,这很愚蠢。 如果我的整个键盘变成红色,我会注意到。 再次,环境。 如果您愿意的话,我当然可以添加警报并让“克拉克森”号熄灭。

#!/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.

这个本地键盘API旨在将信号发送到单个区域或按键,因此我(真的是他们)很讨厌进行100多次REST调用来给整个键盘着色。 但是,这是一个localhost调用,并不是那么花钱。 当我转向他们的新API时,这将消失。 这是一个工作正常的视频

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

您还可以按键盘上的任何“已信号”(点亮)键来敲击音量按钮,并弹出带有实际血糖值的弹出窗口(上面第二个curl命令中的“消息”)。 同样,这是一个hack,但是我将使其变成一个正式的applet,您可以从商店中进行安装。 如果您想提供帮助(我很慢),请转到此处的代码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)

得到了我的键盘上的按键改变颜色*当我的血糖上升!* @daskeyboard @NightscoutProj #WeAreNotWaiting #diabetes pic.twitter.com/DSBDcrO7RE

-Scott Hanselman(@shanselman) February 8, 2019 2019年2月8日

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

环境糖警报还有哪些其他好主意? 显示器周围是否有LCD条(偏光)? Phillips Hue智能灯?

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.

赞助商:使用Code Vision,重命名项目重构和Assembly Explorer,获取最新的JetBrains Rider 。 包括对C#, VB.NET ,F#,TypeScript和Angular的改进支持。

翻译自: https://www.hanselman.com/blog/lighting-up-my-daskeyboard-with-blood-sugar-changes-using-my-bodys-rest-api

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值