Scott Hanselman

Enabling Websockets for Socket.io Node apps on Microsoft Azure

November 3, '14 Comments [13] Posted in Azure | Diabetes | nodejs | Open Source
Sponsored By

Whoa my Blood Sugar is a CGM in the Cloud!NOTE: This is a technical post, I'll blog more about Nightscout later this week. Subscribe and watch for my take, or visit http://www.nightscout.info.

I'm running an application called Nightscout that is a node app with a MongoDB backend that presents a JSON endpoint for a diabetic's blood sugar data. I use my Dexcom G4 CGM (Continuous Glucose Meter) connected with a micro-USB OTG cable to an Android phone. An Android app bridges the device and POSTs up to the website.

Azure is well suited to run an app like this for a few reasons. Node works great on Azure, MongoLabs is setup in the Azure Store and has a free sandbox, Azure supports WebSockets, and *.azurewebsites.net has a wildcard SSL cert, so I could force SSL.

Enabling Websockets and Forcing SSL

So my goal here is to do two things, make sure Websockets/socket.io is enabled in my app because it's been using polling, and force my app to use SSL.

Setting up a node.js site on Azure is very easy. You can see a 3 minute video on how to do a Git Deploy of a node app here. Azure will see that there's a app.js or server.js and do the right thing.

However, because IIS and node are working together to host the site (IIS hands off to node using a thing called, wait for it, iisnode) you should be aware of the interactions.

There's a default web.config that will be created with any node app, but if you want to custom stuff like rewrites, or websockets, you should make a custom web.config. First, you'll need to start from the web.config that Azure creates.

Related Link:  Using a custom web.config for Node apps

Let's explore this web.config so we understand what's it's doing so we can enable Websockets in my app. Also, note that even though our project has this web.config in our source repository, the app still works on node locally or hosts like Heroku because it's ignored outside Azure/IIS.

  • Note that we say "webSocket enabled=false" in this web.config. This is confusing, but makes sense when you realize we're saying "disable Websockets in IIS and let node (or whomever) downstream handle it"
  • Note in the iisnode line you'll put path="server.js" or app.js or whatever. Server.js appears again under Dynamic Content to ensure node does the work.
  • I added NodeInspector so I can do live node.js debugging from Chrome to Azure.
  • Optionally (at the bottom) you can tell IIS/Azure to watch *.js files and restart the website if they change.
  • We also change the special handling of the bin folder. It's not special in the node world as it is in ASP.NET/IIS.
<?xml version="1.0" encoding="utf-8"?>
<!--
This configuration file is required if iisnode is used to run node processes behind
IIS or IIS Express. For more information, visit:

https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config
-->

<configuration>
<system.webServer>
<!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support -->
<webSocket enabled="false" />
<handlers>
<!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
<add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<!-- Do not interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server.js\/debug[\/]?" />
</rule>

<!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
<rule name="StaticContent">
<action type="Rewrite" url="public{REQUEST_URI}"/>
</rule>

<!-- All other URLs are mapped to the node.js site entry point -->
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="server.js"/>
</rule>
</rules>
</rewrite>

<!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin"/>
</hiddenSegments>
</requestFiltering>
</security>

<!-- Make sure error responses are left untouched -->
<httpErrors existingResponse="PassThrough" />

<!--
You can control how Node is hosted within IIS using the following options:
* watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
* node_env: will be propagated to node as NODE_ENV environment variable
* debuggingEnabled - controls whether the built-in debugger is enabled

See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
-->
<!--<iisnode watchedFiles="web.config;*.js"/>-->
</system.webServer>
</configuration>

Next, turn on Websockets support for your Azure Website from the configure tab within the Azure Portal:

Turn on Websockets in the Azure Portal

Now I need to make sure the node app that is using socket.io is actually asking for Websockets. I did this work on my fork of the app.

io.configure(function () {
- io.set('transports', ['xhr-polling']);
+ io.set('transports', ['websocket','xhr-polling']);

It turns out the original author only put in one option for socket.io to try. I personally prefer to give it the whole list for maximum compatibility, but in this case, we clearly need Websockets first. When will Websockets fall back if it's unavailable? What Azure website pricing plans support WebSockets?

  • Free Azure Websites plans support just 5 concurrent websockets connections. They're free. The 6th connection will get a 503 and subsequent connections will fallback to long polling. If you're doing anything serious, do it in Shared or above, it's not expensive.
  • Shared Plans support 35 concurrent websockets connections, Basic is 350, and Standard is unlimited.

You'll usually want to use SSL when using Websockets if you can, especially if you are behind a proxy as some aggressive proxies will strip out headers they don't know, like the Upgrade header as you switch from HTTP to Websockets.

However, even free Azure websites support SSL under the *.azurewebsites.net domain, so doing development or running a small site like this one gets free SSL.

I can force it by adding this rule to my web.config, under <system.webServer>/<rewrite>/<rules/>:

<rule name="Force redirect to https">
<match url="(.*)"/>
<conditions>
<add input="{HTTP_HOST}" pattern=".+\.azurewebsites\.net$" />
<add input="{HTTPS}" pattern="Off"/>
<add input="{REQUEST_METHOD}" pattern="^get$|^head$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}"/>
</rule>

Note the pattern in this case is specific to azurewebsites.net, and will take any Azure website on the default domain and force SSL. You can change this for your domain if you ike, of course, assuming you have an SSL cert. It's a nice feature though, and a helpful improvement for our diabetes app.

I can confirm using F12 tools that we switched to WebSockets and SSL nicely.

image

The whole operation took about 15 minutes and was a nice compatible change. I hope this helps you out if you're putting node.js apps on Azure like I am!


Sponsor: Big thanks to Aspose for sponsoring the feed this week! Working with Files? Aspose.Total for .NET has all the APIs you need to create, manipulate and convert Microsoft Office documents and many other formats in your applications. Start a free trial today.

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
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web

Diabetics: It's fun to say Bionic Pancreas but how about a reality check

June 30, '14 Comments [23] Posted in Diabetes
Sponsored By

A diagram outlining the complete bionic pancreas systemThe state of healthcare reporting is just abysmal. It's all link-bait. It's fun to write things like "Random Joe invents cure for diabetes in his garage, saves dying 5 year old." It's surely less fun to read them with you're the one with the disease.

IMPORTANT UPDATE: Scott (me) has now interviewed Dr. Steven Jon Russell, MD, PhD, a member of the Bionic Pancreas Team! Check out their interview at http://hanselminutes.com/431.

It's time for medical journalists to try a little harder and pushback against editors that write headlines optimized for pageviews. The thing is, I've met a dozen General Practitioners who are themselves confused about how diabetes works, and link-bait journalism just ruins it for the public, too. I've received no fewer than 50 personal emails or FB posts from well-meaning friends this last week. "Have you heard? They've cured your diabetes with a bionic pancreas!"

I have been a Type 1 Diabetic for 20 years, I've worn an insulin pump 24 hours a day for the last 15 years (that's over 130,000 hours, in case you're counting), I'm a diabetes off-label body hacker with an A1C of 5.5%. What's that mean to you? I'm not a doctor, but I'm a hell of a good diabetic.

I know what I'm talking about because I'm living it, and living it well. A doctor may be able to tell me to adjust my insulin every 3 months when I see them, but they aren't up with me at 4 am in a hotel in Germany with jet-lag telling me what to do when I'm having a low. Forgive me this hubris, but it comes from 75,000 finger pricks and yes, it hurts every time, and no, my insulin pump doesn't automatically cure me.

Last year the FDA approved an Insulin Pump that shuts off automatically if it detects the wearer is having a low sugar. The press and the company itself called this new feature an "artificial pancreas." Nonsense. It's WAY too early to call this Insulin Pump an Artificial Pancreas.

Now we are seeing a new "bionic" pancreas for which that the press is writing headlines like "A Father Has Invented a Bionic Organ to Save His Son From Type 1 Diabetes" and "Bionic Pancreas" Astonishes Diabetes Researchers."

It's a great proof concept for a closed system based on dual insulin pumps (one with glucagon) and a high accuracy CGM managed by an iPhone. But that's a not a fun headline, is it?

"Boston University biomedical engineer Ed Damiano and a team of other researchers published a study earlier this month detailing a system that could prevent these dangerous situations."

Indeed, the study in the New England Journal of Medicine where Ed Damiano, Ph.D. is listed alongside Steven J. Russell, M.D., Ph.D., Firas H. El-Khatib, Ph.D., Manasi Sinha, M.D., M.P.H., Kendra L. Magyar, M.S.N., N.P., Katherine McKeon, M.Eng., Laura G. Goergen, B.S.N., R.N., Courtney Balliro, B.S.N, R.N., Mallory A. Hillard, B.S., David M. Nathan, M.D.

They are clearly all brilliant and of note. Let's break the study down.

"...we compared glycemic control with a wearable, bihormonal, automated, “bionic” pancreas (bionic-pancreas period) with glycemic control with an insulin pump (control period) for 5 days in 20 adults and 32 adolescents with type 1 diabetes mellitus."

They are trying to improve blood sugar control. That means keeping my numbers as "normal" as possible to avoid the nasty side-effects like blindness and amputation in the long-term with highs, and death and coma with lows. The general idea is that since my actual pancreas isn't operating, I'll need another way to get insulin into my system. "Bihormonal" means they are delivering not just insulin, which lowers blood sugar, but also glucagon, which effectively raises blood sugar. They tested this for 5 days on a bunch of people.

"The device consisted of an iPhone 4S (Apple), which ran the control algorithm, and a G4 Platinum continuous glucose monitor (DexCom) connected by a custom hardware interface."

I use a DexCom G4, by the way. It's a lovely device and it gives me an estimate of my blood sugar every 5 minutes by drawing a parallel between what it detects in the interstitial fluid of my own fat and tissues (not my whole blood) and then sends it wirelessly to a handset. I currently then make calculations in my head and decide (Note that keyword: decide) how much insulin to take. I then manually tell my Medtronic Insulin Pump how much insulin to take. The DexCom must be calibrated at least twice daily with a whole blood finger stick. Also, it's not too accurate on day 1, and can be wholly inaccurate after it's listed 7 day effectiveness range. But it's that keyword that this project is trying to help with. Decide. I have to decide, calculate, guess, determine. That's hard for me as an adult. It's near-impossible for an 8 year old. Or an 80-year old. Computers are good at calculating, maybe it can do this tedious work for us.

It's two pumps, one with insulin, one with glucagon, and an iPhone controlling them both

The thing is, with Type 1 Diabetes there's dozens of other factors to consider. How much did I eat? What did I eat? Am I sick? Does my stomach work? Do I digest slowly? Quickly? Do I have any acetaminophen in my system? Am I going jogging afterwards? Is this insulin going bad? Is the insulin pump's cannula bent, and dozens (I'm sure I could come up with a hundred) of other factors. Read Lane Desborough's paper (PPT as a PDF) on "Applying STPA (System Theoretic Process Analysis) to the Artificial Pancreas for People with Type 1 Diabetes" for a taste of what needs to be done.

image

The brilliance of this system - this "bionic" pancreas - is this...and these are MY words, no one else's:

The two pump bionic pancreas system gives you rather a LOT of insulin if needed (as if it's descending a plane quickly and dramatically) then it pulls you up nicely with a bit of glucagon (as if the pilot screamed pull up as he noticed the altitude change).

It's the addition of the glucagon to get you out of lows that is interesting. Typically Diabetics have a big syringe of glucagon in the fridge for emergencies. If you're super low - dangerously loopy - your partner can get you out of it with a big bolus of glucagon. But if you put glucagon in an insulin pump, you can deliver tiny amounts and now you are are moving the graph in two directions.

Think I'm kidding about the "pull up, pull up" analogy?

Here's a snippet of a graph from page 15 of one of the Appendices (PDF). Note around 19:00, the blue bar going down, that's a lot of insulin. Then the BG numbers come down, FAST. Note the black triangle at around 20:20. That's "pull up, pull up" and a bolus of glucagon in red. And more, and more, in fact, there are many glucagon boluses keeping the numbers up, presumably happening while the subject sleeps. Then around 07:00 the numbers rise, presumably from the Dawn Effect, and another automatic insulin bolus (an overcorrection) and then more glucagon. It's a wonderfully controlled roller-coaster. This isn't using the word roller-coaster as a pejorative - that is the life I lead as a diabetic.

Pull up, pull up!

It's also not mentioned in the press that this system uses lot more insulin than I do today. A lot more, due to it's "dose and correct" algorithm's design.

"Among the other 11 patients, the mean total daily dose of insulin was 50% higher during the bionic-pancreas period than during the control period (P=0.001);"

UPDATE: I spoke to Dr. Russell, and I'm not entirely correct that this system uses a lot more insulin. The system didn't use much more insulin in diabetic kids who have very controlled diets, and was 50% higher in only some of the adults, presumably because (anecdotally) many of them were eating a lot more and "testing" the extents of the system.

I use about 40U a day, total. So we're looking at me using perhaps 60U a day with this system. As with any drug, though, insulin use has its side effects. It can cause fat deposits, scarring at injection sites, and we can become resistant to it. It'd be interesting to think about a study where someone's on 50% more insulin for years. Would that cause increases in any of these side effects? I don't know, but it's an interesting question. Should a closed system also optimize for doing its job with the minimum possible insulin. I optimize for that today, on my own, hoping that it will make a difference in the long run.

But, glucagon isn't pump friendly as it is today. An unfortunate note that isn't covered in any of the press is that they are having to replace the glucagon every day. Juxtapose that with what I do currently with insulin. I keep my pump filled and swap out its contents and cannula (insertion site) every 4-7 days. Insulin itself can surface ~28 days at room temperature although it's most often refrigerated. Changing one of the pumps daily is a bummer, as they point out.

"...the poor stability of currently available glucagon formations necessitated daily replacement of the glucagon in the pump with freshly reconstituted material."

It's early, people. It's not integrated, it's a proof of concept. It's impressive, to be sure, but Rube-Goldbergian in its hardware implementation. Two pumps, a Dexcom G4 inside a docking station, receiving BG data over RF from the transmitter, then the Dexcom wirelessly talking to an iPhone within another docking station.

"Since a single device that integrates all the components of a bionic pancreas is not yet available, we had to rely on wireless connectivity to the insulin and glucagon pumps, which was not completely reliable."

I'm not trying undermine, undercut, or minimize the work, it's super promising, but medical journalists need to seriously understand what's really going on here.

Fast forward a few years, and there will very likely be an bi-hormonal "double" pump with both (more stable) glucagon and insulin that combines with a continuous glucose meter that provides the average Type 1 Diabetic with a reasonable solution to keep their numbers out of imminent danger. Great for kids, a relief for many.

But, just as pumps are today, it'll be USD$5000 to USD$10000. It will require insurance, and equipment, it'll require testing and software, it'll require training, and it won't be - it can't be - perfect. This is a move forward, but it's not a cure. Accept it for what it is, a step in the right direction.

Do I want it? Totally. But, journalists and families of diabetics, let's not overreact or get too ahead of ourselves. Does this mean I should eat crap and the machine will take care of it? No. I'm healthy today because I care to be. I work at it. Every day. As I'm typing now, I know my numbers, my trend-line, and my goal: stay alive another day.

Read my article from 2001 - yes, that's 13 years ago - called One Guy, an Insulin Pump, and 8 PDAs:

"I imagine a world of true digital convergence -- assuming that I won't be cured of diabetes by some biological means in my lifetime -- an implanted pump and glucose sensor, an advanced artificial pancreas. A closed system for diabetics that automatically senses sugar levels and delivers insulin has been the diabetics' holy grail for years. But with the advent of wireless technology and the Internet, my already optimistic vision has brightened. If I had an implanted device with wireless capabilities, it could be in constant contact with my doctor. If the pump failed, it could simultaneously alert me, my doctor, and the local emergency room, downloading my health history in preparation for my visit. If it was running low on insulin, the pump could report its status to my insurance company, and I'd have new insulin delivered to my doorstep the next day. But that's not enough. With Bluetooth coming, why couldn't my [PDA] monitor my newly implanted smart-pump?"

Go an educate yourselves about the "We Are Not Waiting" movement. Hear how Scott Leibrand has a "DIY Artificial Pancreas" that's lowered his girlfriends average blood sugar dramatically using only an DexCom G4 and smart algorithms. You can make a change today, at your own risk, of course.

Read about the The DiabetesMine D-Data ExChange and how non-profit Tidepool is creating open source software and systems to make innovation happen now, rather than waiting for it. Get the code, join the conversation. Exercise, eat better, read, work. You can hack your Diabetes today. #WeAreNotWaiting

Related Links and Writings


Sponsor: Thanks to friends at RayGun.io. I use their product and LOVE IT. Get notified of your software’s bugs as they happen! Raygun.io has error tracking solutions for every major programming language and platform - Start a free trial in under a minute!

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
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web

It's WAY too early to call this Insulin Pump an Artificial Pancreas

September 29, '13 Comments [41] Posted in Diabetes
Sponsored By

app_6_steps_621

The diabetic internet and lots of mainstream news agencies are abuzz about the new insulin pump from Medtronic. Poorly written news articles that are effectively regurgitations of the Medtronic Press Release have exciting headlines like this:

Other news outlets have slightly better headlines like

But then ruin it with vague subtitles that are missing important context:

  • FDA approved the company’s automated insulin delivery system.

This is Step 1, possibly Step 0.

TO BE CLEAR. This new Medtronic 530G pump is NOT an artificial pancreas. It is an insulin pump, similar to the very model I'm wearing right now. It is paired with a revision of Medtronic's CGM (Continuous Glucose Meter) system and it does one new thing.

This new pump will turn off if you ignore its alarm that you may be having a low blood sugar.

Read it again, I'll wait.

Note the JDRF chart above describing the steps we need to towards a true artificial pancreas. This new 530G from Medtronic is arguably Step 1 in this 6 step process. It's the first step of the first generation.

But wait, doesn't your pump just handle things for you? You don't have to stick your fingers anymore, right? Wrong.

Let's stop and level set for a moment. Here's a generalization of your day if you're not diabetic.

image

Here's what a Type 1 diabetic (like me) does:

image

If I get this new pump that news outlets are incorrectly calling an artificial pancreas will anything in this cycle change? No.

There's NOTHING automatic here. I want to make that clear. Today's insulin pumps are NOT automatic. I set them manually, I tell them what to do manually. Yes, they "automatically deliver insulin as I sleep" but only because I told it to. If I eat and do nothing, I WILL get high blood sugar and today's insulin pumps will do exactly NOTHING about it.

If I only make decisions about insulin dosage based on my CGM then I WILL eventually get in trouble because today's CGMs are demonstrably less accurate than finger sticks. And, here's the kicker, finger sticks aren't even that accurate either.

Even more insidious is the issue of lag time. Medtronic's last generation of CGM lagged by 20 to 30 minutes BEHIND a finger stick. That meant I was getting "real time values" that in fact represented my blood sugar in the past. It's hard to make reliable altitude changes in your plane if your altimeter shows your altitude a half hour ago.

The Medtronic Press Release says that this new Enlite Sensor is 31% more accurate. I hope so. I personally continue to use a Medtronic 522 pump (this new one is the 530G) but I have given up on Medtronic's CGM in favor of a Dexcom G4. I am thrilled with it. The G4 has about a 5 minute lag time and is astonishingly accurate.

NOTE: I have no personal or investment relationship with either Dexcom or Medtronic. I am not a doctor or a scientist. I write this blog post with the expertise of someone who has been a Type 1 Diabetic for 20 years, a user of a Medtronic Pump for 15 years, a user of a Medtronic CGM for 4 years, and more recently a user of a Dexcom G4 for a year. My most recent A1C test was 5.5 putting my blood sugars at near non-diabetic levels on average. TL;DR - I'm a very good diabetic who uses the best available technology to keep me alive as long as possible.

I am extremely disappointed in the lack of research, due diligence and basic medical common sense in these articles. If you are a Type 1 Diabetic or have someone in your life who is, do the research and the reading and please spread the word so people can make informed decisions.

Related Reading

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
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web

Hacking Diabetes

October 5, '12 Comments [41] Posted in Diabetes
Sponsored By

Photo by cogdogblog used under CCNOTE: The top part of this post is background and basics. If you are a diabetic who wants the advanced techniques, they are further down a bit.

Being a Type 1 diabetic sucks. But, if you know anyone who is diabetic then you likely already know that. Over the last twenty years I've tried  many different drugs, diets, techniques, and hacks all meant to keep me alive as long as possible. Diabetes is the leading cause of blindness, liver failure, kidney failure and a bunch of other stuff that also sucks. It would be really awesome to die of regular old age rather than some complication of diabetes.

Every few months a diabetic should get a blood test call an hA1c that is a measure of long term blood sugar control. A normal person's A1C is between 4% and 6% which roughly corresponds to a 3 month average blood sugar of between 70 and 120mg/dl, which is great. My A1c has been around 6.0 to 6.7 which is under the American Diabetes Association's recommendation for Type 1 diabetics of 7.0, but not as low as I'd like it.

Related Reading

I recently redoubled my efforts and lost about 30lbs, started working out more and removed more carbohydrates by implementing a relaxed paleo diet. This, combined with some medical equipment changes that I discuss below have resulted in my latest A1c - just in last week - of 5.7%. That means for the first time in nearly 20 years I have maintained near-normal blood sugar for at least 3 months.

Basics

A Type 1 diabetic doesn't produce any insulin, and insulin is required to process sugar and deliver it to the cells. Without insulin, you'd die rather quickly. There's no diet, no amount of yoga, green tea or black, herbs or spices that will keep a Type 1 diabetic alive and healthy. Type 1 diabetes is NOT Type 2 diabetes, so I'm not interested in your juicers, raw food diets or possible cures. I've been doing this with some success for the last two decades and I plan to continue - also with success - for the next two.

If you blood sugar gets too high you'll die slowly and rather uncomfortably. If your blood sugar gets too low you'll die rather quickly (or at the very least lose consciousness). The number one goal for a Type 1 Diabetic is to effectively manage insulin and blood sugar levels by simulating a working pancreas where there isn't one. You eat food and your blood sugar rises. You take insulin and your blood sugar lowers. You can prick your finger and check your blood sugar directly then perform some calculations and inject yourself with insulin. If everything works out well then your blood sugar is stable just like a "normal" non-diabetic.

Unfortunately it's never that easy, and in the case of Type 1 diabetes there's a number of factors that complicate things. Sometimes blood sugar rises on its own, sometimes due to illness, hormones, or any of a dozen other factors. The most difficult issue to deal with is that of lag time. When you check your blood sugar you're actually looking at the past. You're seeing your blood sugar in the past, sometimes 15-20 minutes ago. When you take insulin it won't start working for at least 30 minutes, often as long as 60 to 90 minutes. I talk about this in my post Diabetes: The Airplane Analogy. Try flying a plane where your altimeter shows you the past and altitude adjustments are all delayed. I would imagine it's not unlike trying to pilot the Mars Lander. Sadly, there is no such thing as "real time" when it comes to diabetes management.

Basic Management

Basic blood sugar management typically comes down to carb counting and insulin dosage. You'll learn from a Diabetes Educator that your body (everyone is different) will react to insulin in a certain way. You'll learn that, for example, your insulin to carbohydrate ratio might be 1U (1 unit of insulin) to 15g (grams) of carbohydrate. You'll read food labels and if there's a cookie with 30g of carbohydrates or sugars that you'll need to "cover" it with 2U of insulin.

That's the basics. Things quickly get complicated because not all sugars are alike. A cookie with 30g of carbs will "hit you" - or cause a blood sugar rise - much faster than an apple with 30g of carbs or mixed nuts with 30g of carbs. The speed at which carbs hit you is known as the glycemic index of the food. Fruit juices, starches, candy, all have high glycemic indexes.

Why should a diabetic care about how fast food raises their blood sugar? Because the faster your blood sugar moves the hard it is it control. If a cookie can raise blood sugar in 15 minutes but insulin won't start lowering it for an hour you can see how a daily rollercoaster of blood sugar spikes can get out of control.

A reasonably low carb diet makes Type 1 diabetes much easier to handle and manage. I avoid bread, sugar and anything "white." That means no white rice, no white bread, no white sugar. If I'm going to have bread, it'll be whole grain or sprouted wheat.

Portion Size and Cutting Carbs

You should rarely be eating a meal that is larger than your own fist. Better you eat 6 fist-sized meals than 3 giant plates a day. Reasonable portions avoid high sugar spikes.

Cutting carbs is surprisingly easy. I've done personal experiments with hamburgers, for example. A hamburger might require me to take 6U of insulin but that same hamburger minus the top bun was only 3U. It was still satisfying and yummy but that top bun was just empty carbs. That leaves more room for salad (with dressing on the side) which is a diabetic's "free food." You can eat raw veggies until you're bloated and in some cases take no insulin at all, while a Small French Fry could literally set you on a miserable rollercoaster of a day.

Fries and starches are simply off limits. If you eat them, you will pay the price. Pizza, potatoes, tubers of any kind are all effectively raw sugar. Same with all fruit juices and any HFCS (High Fructose Corn Syrup.) In fact, any "-ose" is ill-advised, including Fructose, Glucose and Dextrose.

The Poor Man's Pump

Not that many years ago insulin came in many speed variations. Some were long acting and some short. In recent years we've standardized on two kinds, very long acting where one shot lasts for 24 hours, and fast acting where one shot starts in about an hour and is gone in about four.

We need some insulin running in the background all the time just to stay stable. This is all the basal rate or background insulin. Then when we eat we need a bolus of insulin to "cover" a meal. Long acting insulin can act as the basal and short acting as the bolus.

For those that don't have an insulin pump (more on that later) a pump can be simulated by a long acting shot of an insulin like Lantis/Glargene once a day to act as a basal and then short acting insulins like Humalog/Novalog/Apidra for means. You can simulate about 80% of a pump with this "poor man's pump."

Insulin Pumps

Photo by cogdogblog used under CCIf you've got an insulin pump like I have then you actually have no long acting insulin in you. Instead you've literally got a pump and a tube dripping insulin into your body. I've worn one 24 hours a day, while asleep and awake for over a decade.

So where's the basal or background insulin coming from? The pump actually contains only short acting insulin but delivers it in extremely precise and tiny increments all the time. For example, I usually have my pump delivering 0.5U/hr all the time.

Note that none of this is automatic. Pumps are not automatic systems and will only do what you tell them, fortunately or unfortunately. If you're willing to put some thought and effort into it you can do some interesting things with pumps that you simply cannot do with MDI (Multiple Daily Injections.)

Square Wave Basal (Buffet Mode)

One of the things a pump can do that injections simply can't is basal adjustments. Once you've taken a long-acting insulin shot, it's in you and it's going to do its work for 24 hours. The only thing you can do with insulin in you already is add more food or more insulin.

With a pump, though, you can program a either a Square Wave Bolus or a temporary Basal. This can be useful when at an event where you'll be "grazing" and eating little bits over a long period, or in situations where you're eating foods that will take a long time to digest, like pizza.

Temporary basals are also useful for exercise and activity. You can temporarily lower your background insulin for a few hours while you're hiking, for example. Lowering your basal temporarily is your best way to avoid exercise-related lows.

Often Type 1's get into trouble exercising because they'll work out, burn a hundred calories, have a low blood sugar, then eat a few hundred calories thereby negating the original exercise. Lower your basal an hour or so before exercise and set a timer to keep it low for an hour or two. Better an exercise-induced high than an exercised-induced low.

Temporary Basals while crossing Time Zones

I do a lot of international travel and often cross a number of time zones in a single trip as a diabetic. Diabetics on pumps often have multiple basals rates programmed on a schedule and this can cause issues when going overseas.

For example, here's mine:

  • 3am - 0.75U/hr
  • 8am - 0.5U/hr
  • 6pm - 0.6U/hr
  • 12am - 0.5U/hr

The 3am to 8am boost there is to manage the blood sugar rise known as the "dawn phenomenon." It's your body trying to get you ready for the day. It's part of your circadian rhythm and it's great for you. It's lousy for me though as it means my blood sugar will just start rising unchecked starting at about 4am.

When travelling, though, what's dawn to me? ;) It takes about a day to adjust for every time zone crossed. So even though I was just in Europe for a week, my "dawn" was slowly moving from the west coast of the US over the Atlantic all week. I needed to be aware of this as I set my pump's clock.

If you change your pump's clock to the destination time zone on the first day, your basals won't reflect your physical reality. You'll get more insulin at 3am local time, for example, but you likely needed it 4 or 7 hour before.

I've found that for simplicity's sake I set my basals while travelling to two 12-hour values, night and day. For example, on this trip I set to 0.6U/hr during the day and 0.5U/hr during the night. This allowed me to see when the dawn rise was happening and deal with it using a bolus, rather than risking a nasty and unexpected low at a seemingly random time. Use temporary basals to smooth things out. I'll set 4 and 6 hour temporary basals as well to "tap it down" or "float up."

Super BolusPhoto by kirinqueen used under CC

One of the most advanced and most powerful techniques is the Super Bolus. I tend to be a little prejudiced against CDEs (Certified Diabetes Educators) (sorry, friends!) unless they are diabetic themselves. No amount of education can match 24 hours a day, 7 days a week for 20 years. The Super Bolus is one of those techniques that we find after hard work and 3am suffering.

Since even fast-acting insulin often isn't fast enough you'll sometimes want a way to give yourself more insulin now without an unexpected low in 2 to 4 hours.

What you can do is turn off your pump effectively by setting a temporary basal of 0U/hr, and then give yourself the saved amount on top of your planned bolus.

Here's an example. You want to have some ice cream. You take 5U of insulin, your basal is 0.5U/hr. You eat the ice cream and have a bad high sugar in an hour and then a nasty low 3 hours out. The insulin didn't move fast enough to cover the ice cream, and when it did finally start working it took you low because your basal was ongoing.

Instead, you could take 6.5U of insulin and set a 3 hour temporary basal of 0U/hr. You have taken the 1.5U that would have been spread out over 3 hours and instead stacked it on top of the big bolus. The net amount of insulin is the same! You're just clipping that big high and bypassing that nasty low.

You'll need to find numbers that work for you, but the Super Bolus is a powerful technique for avoiding highs and still being able to eat some carbs.

Off-Label Drugs

There are a number of interesting new drugs out for diabetics that aren't super common but if you're interested in hacking your diabetes and you have a willing endocrinologist they could help you.

Symlin is a brand name synthetic amylin and replaces another missing hormone in Type 1 diabetics. Symlin is another shot you would have to take in addition to insulin. We tend to digest food really quickly and that causes nasty post-prandial (after eating) blood sugar spikes. Symlin will slow your digested to that of a normal person and clip those high sugars and allow your insulin to work. Talk to your doctor because it's serious stuff and not to be trifled with. Symlin induced low blood sugars can be really challenging to pull up out of. If you can get past the first two to four weeks of nausea it can be a powerful tool. I took Symlin for a number of years but now I only use it for a few large meals a year like Thanksgiving and Christmas.

Victoza is a new drug for Type 2 diabetics and is explicitly not recommended for Type 1s. However, if your doctor feels it would help you as a Type 1 it can be given "off label." It is a GLP1 inhibitor that also slows absorption of food and its movement through the gut. Finding the right dose can be a challenge, but since Victoza is a daily injectable you can adjust the dose one day at a time.

UPDATE/Correction from Karmel: "Minor point, but Victoza and Bydureon are GLP1 (with a P for glucagon-like peptide) agonists (that is, analogs)-- they mimic the action of GLP1, not inhibit it. Some T2 drugs with similar effects like Januvia are DPP-4 inhibitors, where DPP-4 inhibits GLP1, making a DPP-4 inhibitor a positive regulator of GLP1. But GLP1 we want"

Bydureon has a similar effect to that of Victoza except you take it once a week. It's also a Type 2 drug that is off label for Type 1s. It takes about a month to build up in the system before you see its effects and it can also cause significant nausea.

Order of Food

What a silly heading, but yes, the order you eat can affect your blood sugar. If you drink juice and eat bread before eating a chicken breast your blood sugar will rise faster than if you eat the chicken breast first. If you have a meal with fat in it then eating the fatty part of the meal will slow down whatever comes next. While cheese isn't really good for you, you can slow down the food that comes after it by eating cheese before crackers and an apple, for example.

Lowering A1C by Sleeping

Here's another trick that was so fundamental to getting my A1c down. You're asleep for 6 to 10 hour a day. Nearly a third of your life you're asleep. This is the perfect time to have great blood sugar. There are few feelings worse as a diabetic than waking up after a long night only to discover that you've had high blood sugar all night long. You've been marinating in your own sugar and you didn't even know. What a horrible feeling.

I try not to eat after 8pm so that I have from 8pm until I go to sleep to even out my numbers. You want your numbers to be either normal or heading clearly towards normal as you go to sleep. Just as they say for a good marriage you should never go to bed angry. I say for good A1c results you should never go to bed with bad blood sugar. Even if your numbers are garbage all your waking hours at least try to get them smooth and low as you sleep. Avoid doing anything to move them around after dinner. Eat your dinner, get back to normal, then have a basal rate you can count on and set it for as long as you can.

Equipment

Always be on the lookout for equipment that might allow you to better manage your blood sugar. Sometimes this is covered by insurance, sometimes it's not. It never hurts to ask your insurance company or your doctor.

I've used a Medtronic insulin pump with an integrated CGM for years. It's a good integrated system but the CGM has as considerable lag time showing my blood sugar about 20 minutes in the past. I have also been unimpressed with my OneTouch Mini blood sugar meter. I grow tired of calibrating and coding the meters and I also feel they aren't nearly as accurate as one needs for tight control.

This year I moved from my Medtronic Paradigm Continuous Glucose Meter (CGM) to a Dexcom Seven CGM. I also switched from a OneTouch Mini to a OneTouch Verio.

The OneTouch Verio is a near codeless meter from OneTouch. That means I can just plug in a strip without entering any codes or calibrations. It is rechargeable with a standard mini-USB adapter and it even as a lighted sensor area so you can check your numbers at the movies. (This is a bigger deal than you might realize.)

The Verio, in my opinion, skews high in its readings. When compared to the OneTouch Mini the Verio values are consistently 20mg/dl higher. This is actually a good thing because when calibrated with the Dexcom CGM it nudges me towards an even lower blood sugar goal.

The Dexcom Seven CGM is the single greatest piece of new technology I've ever experience since I was diagnosed at age 20. It's so profoundly amazing and so utterly indispensible I truly can't imagine life without it. It reduced the lag time for my readings from 20 minutes to less than 5. It's far more accurate than the Medtronic and the sensors can stay in for a week or more. It doesn't provide as much historical data as the Medtronic but the accuracy of the Dexcom is a thing to behold. I'm looking forward to the new Animas Vibe with the Dexcom integrated and plan on switching the nanosecond it comes out. Even though the Dexco is yet another thing to carry and keep charged I credit this CGM with helping me get the best A1c test results of my diabetic life thus far.

As with all random blog posts your read on the internet, remember this. I'm not a doctor. I'm just a random dude you don't know. Try all this at your own risk and under your doctor's supervision.


If you'd like to make a tax-deductible donation to the American Diabetes Association and be a part of Team Hanselman, you can donate securely here http://hanselman.com/fightdiabetes/donate. It is appreciated!

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
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web

The Sad State of Diabetes Technology in 2012

June 17, '12 Comments [118] Posted in Diabetes
Sponsored By

animation1I've been diabetic for almost two decades. It's tiring, let me tell you. Here's a video of my routine when I change my insulin pump and continuous meter. I'm not looking for pity, sadness or suggestions for herbs and spices that might help me out. I'd just like a day off. Just a single day out of the last 7000 or the next, I'd like to have a single piece of pie and not chase my blood sugar for hours.

Every time I visit the doctor (I do every 3 months) and every time I talk to someone in industry (I do a few times a year) I'm told that there will be a breakthrough "in the next 5 years." I've been hearing that line - "it's coming soon" - for twenty.

I used to wait a minute for a finger stick test result. Now I wait 5 seconds but we still have blood sugar strips with +-20% accuracy. That means I can check my sugar via finger stick twice and get a number I'd take action on along with one I wouldn't. Blood sugar strip accuracy is appalling and a dirty little secret in the diabetes community.

I started with insulin that would reach its peak strength after about 4 hours. Today it takes about an hour. Awesome, but that's not fast enough when a meal can take me to the stratosphere in minutes.

We are hurting here and we can't all wait another five years. Diabetes is the leading cause of blindness, leading cause of kidney failure and leading cause of amputation.

I wrote the first Glucose Management system for the PalmPilot in 1998 called GlucoPilot and provided on the go in-depth analysis for the first time. The first thing that struck me was that the PalmPilot and the Blood Sugar Meter were the same size. Why did I need two devices with batteries, screens, buttons and a CPU? Why so many devices?

NewColorSmall_smallIn 2001 I went on a trip across the country with my wife, an insulin pump and 8 PDAs (personal digital assistants, the "iPhones" of the time) and tried to manage my diabetes using all the latest wireless technology. Here's what I had to say 11 years ago:

With Bluetooth coming, why couldn't my [PalmPilot] monitor my newly implanted smart-pump? GlucoPilot could generate charts and graphics from information transmitted wirelessly from the pump. For that matter, the pump, implanted in my abdomen, could constantly transmit information to Bluetooth-enabled devices that surround me. The pump might use my cell phone to call in its data into a central server when I'm not using the phone. If I wander near my home computer, the pump or Visor might take the opportunity to upload its data. During a visit to the doctor, Bluetooth's 30-meter range could provide the doctor with my minute-by-minute medical history as I sat in the waiting room.

Back in 1998 when I was writing and marketing GlucoPilot I was using a custom cable that connected directly from my PalmPilot to the glucose meter and downloaded my historical glucose data. Fast forward to 2012 and what new technologicals innovation do we have?

Yes, that's a custom cable to plug-in to my PDA. Yes, I'm a frustrated diabetic. This a 15 year old solution with no backing standards, no standard interchange format, no central cloud to store the data in. It's vendor lock-in on both sides.

Kudos to the Glooko guys for fighting the good fight and shame on the blood sugar meter manufacturers for making their job hard.

iphone_cable_meter

Fifteen years ago we talked about data standards and interoperability. I was even on a standards board for a while to try and pressure the industry to standardize on data interchange formats. I have personally written multiple blood sugar meter data importers from the very simple (CSV) to the very complex (binary packed and purposely obscured to prevent 3rd party data dumps) and I can tell you that the blood sugar meter manufacturers are not interested in making it easy to move our data around. This is a billion dollar industry.

Today I read an article about the iBGStar (a forgettable name) glucose meter that plugs directly into an iPhone 30 pin port. The article came up on Hacker News and one of the designers said this in a comment:

I'm one of the designers of the iBGStar and we considered Bluetooth. We actually have another FDA cleared product that uses Bluetooth, but cost, battery life, and a bunch of technical issues led us to favor the 30 pin.

iBGStar-IPhoneThis is hugely disappointing especially since Bluetooth 4.0 is said to offer battery life as long as 10 years on some products. Given all the new iPhones have Bluetooth 4.0 just waiting for devices to connect to, you'd think this is a perfect opportunity for a Bluetooth 4.0 glucose meter.

I appreciate the attempts and the word that is being done in the space, I truly do, but as an end user when I see products like this that are trying to push the envelope but fail with fundamental usability issues, I'm saddened. Most diabetics check their blood sugar 10 times a day or more. I can't keep this glucose meter attached to my phone. It'll fall off, get bent, mess up the 30 pin connector. It's simply not reasonable for a day to day use coming in and out of pockets.

A more reasonable mode of usage would mirror the FitBit. It's tiny, clips to my belt and automatically notices when I pass by my computer then uploads its data wirelessly. That's how wireless is supposed to work. And the battery lasts at least a week.

Twenty years and no significant moves. We are still wiring our devices together, translating from one format to another, all the while being hamstrung by the FDA and their processes. When we do start to get something working well, it's attacked and we're told that our insulin pumps can be hacked from a mile away and we can be killed in our sleep. This will no doubt slow progress and make the FDA even more paranoid when approving new technology.

I've just this week switched from a Medtronic Continuous Glucose Meter to a DexCom, which is another company. This new CGM gives me more accurate data with less lag time. However, I still have the same insulin pump. This means my meter and pump aren't integrated so I carry another device on my person. This is because while the Animas Vibe, a pump that integrates both the DexCom meter and an insulin pump as well as other features like being waterproof, is available EVERYWHERE but the US. It's in the FDA process. Maybe ready in 6 months? 18? Who knows. When it shows up, the technology will be years old while the iPhone is on generation 6. We've got 3D TVs to watch crappy movies on by my insulin pump's firmware hasn't changed in nearly a decade.

The article about the iBGStar is poorly researched and galling.  I appreciate what Hacker News commenter lloyd said with emphasis mine, calling out this inane line from the article.

"Could this be the beginning of mobile diabetes monitoring?"

As so many people above have stated, no, you moron. We've been monitoring blood sugar on the go for the past 30 years.

I've got Type 1 diabetes...and my current meter is smaller than the one shown here. I can plug it into my Mac via USB to download and visualize the data (& can control my insulin pump via bluetooth using the meter).

The only benefit with this particular iPhone-compatible meter would be enhanced, immediate visualization of results. Which might be easier to get, and might not, given the inconvenience of having to remove an iPhone case and plug in the meter. (Not to mention other issues - what if my iPhone's batteries are dead? Will it still work?)

Unfortunately, this product reminds me of 5 years ago, when someone would announce a new toaster, and the tech crowd wouldn't be impressed...unless it was a Bluetooth toaster. We're so focused on it being the hot new thing (it's compatible with iOS! Oooh!!) that we ignore the fact that there's nothing revolutionary being presented here.

The way I see it, this doesn't really change anything in terms of treatment. If it's a more accurate meter, great - sell based on that. Not on the bogus "we're taking blood glucose monitoring mobile" claims.

You may feel like technology is amazing and it's moving so very fast and it surely is. But as a diabetic who relies on technology to stay alive as along as I possibly can, it feels like nothing has changed in 20 years. Maybe something will happen in just 5 more.


Sponsor: I want to thank the folks at DevExpress for sponsoring this week's feed. Check out their DXperience tools, they are amazing. You can create web-based iPad apps with ASP.NET and Web Forms. I was personally genuinely impressed. Introducing DXperience 12.1 by DevExpress - The technology landscape is changing and new platforms are emerging. New tools by DevExpress deliver next-generation user experiences on the desktop, on the Web or across a broad array of Touch-enabled mobile devices.

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
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web
Page 1 of 15 in the Diabetes category Next Page

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