Artem blog

Displaying blood glucose on Xiaomi MiBand fitness trackers

Advertisements

Upd. 29.1.2020 new xDrip version which allows using all MiBand4 features available here https://bigdigital.home.blog/2020/01/23/future-of-the-xdrip-miband-project/

Updates for the this xdrip version would be discontinued.

Introduction

The miband trackers it is a very good device for usual life tracking. There’s a lot to like in Xiaomi trackers. They are cheap and small. For about $40, you get a fitness tracker that has waterproofing, a heart rate monitor, text and call notifications, sleep tracking, workout tracking, and impressive battery life with up to three full weeks, depending on usage.

But they also can be used for originally unintended things.

In my case, the band was used to display a BG low/high alert notification from xdrip application.

Unfortunately, xdrip doesn’t support this band type from the box, so need to use workarounds to receive these notifications.

How to configure notification with the help a thirdparty apps were described in details in this article. https://a.kabachnik.info/blood-sugar-on-a-xiaomi-mi-band.html

But this solution has one disadvantage, to see, the current BG blood level it uses notifications, which usually updates every 5 minutes.  

After the release a MiBand4, i found a cool new thing it this band version. This time Xiaomi lets us to create and upload custom watchfaces .

So a few days ago I discovered a way of changing the watch face for a custom one. And and it took me to the idea that i can create own watchface that will display the values of glucose levels directly on the main screen.

But there was a restriction in realization such watchface. Since the watchface allow to display only time, date, and some status info, I was faced with the task of encoding the values of glucose levels into the available values that miband could display.

For such purposes, the fields of the day of the month, month, and day of the week were most suitable. To display an integer bg value i used a day of the month for decimal value was used a month and to display trend arrow i use a day of the week. In such case, i can display almost any value of the glucose but with one limitation, the maximum integer value could be 18. So if glucose would be more than, 18.9 mmol/L, the watch will display the maximum value as 18.9.

I also added a mg/dl glucose units. To correctly display these units, it is required to install another watchface. For mg watchafe the minimum possible value can be 10mg/dl and maximum value 299 mg/dl.

The watchfaces were designed and compiled with help of the in WF_Builder1.0.4 program can be found here

The watchface bins and source files located by the following links:

upd. Since xdrip version 0.1.3 the xdrip should keep a continuous connection with MiBand, so when miband connected, you will be sure that you see relevant glucose value. If the miband for some reason will lose connections with the phone, you will see a lighting blue indicator in the left bottom corner of the miband so you can consider the value can be outdated. 

No connection with xdrip (the glucose value can be outdated)

Next after this, i made a fork of the xdrip where integrated miband watchface support. Link to xdrip fork https://github.com/bigdigital/xDrip/tree/miband-integration. Link to compiled apk file can be found here xdrip-miband

This version of xdrip can send a notification to miband without any thirdparty tools. Also, it encodes and set the time on miband in a specific format, which allows displaying the BG values in such way:

Also were added a set of settings, which allow to adjust some band settings and see the status.

Unfortunately, the date modification (which required for custom watchface) has own disadvantages.

  1. It is impossible to use standard programs like Mi Fit. They continuously synchronizing time on the watchface, which leads to incorrect bg value displaying. (Note, if you would use thirparty programs, )
  2. The band cannot count steps in a normal way. So you cannot see your fitness progress.
  3. Since miband ver 4, the band developers introduced a new algorithm of the authentication. New devices and older devices with updated firmware require a server based pairing.  So now it is required to obtain an auth key which is normally cannot be extracted from MiFit program, but there exists a workaround (see more details in configuration tutorial)

But if you still want to have all miband features such as fitness progress, steps, sleep, weather, smart alarms, music control and more, it is possible to use notifications to send glucose values (there an option in the miband setting screen which allow to send bg reading as a notification ). In such case, there is no need to install custom watchface.

Configuration tutorial by steps

1. Obtaining auth key

If you want to use xdrip with Mi Band4, you need to get Mi Band 4 Auth key (for the older devices (MiBand2 and Miband3), you can skip this step). The Auth key can be obtained with these simple steps (was copied from https://www.freemyband.com/ )

  1. Unpair band from the existing official app
  2. Uninstall official app
  3. Reset your Mi Band (optional)
  4. Download and install the Mi Fit mod apk version
  5. Login into the Mi Fit with your email
  6. Pair the band
  7. Enable band visibility in the MiFit settings.
  8. Uninstall modified Mi Fit application (If you want to use all miband features, you can install official Mi Fit application again. Login into the Mi Fit with email which was used with patched application and enable “BG readings as notification” option. But in this case would be impossible to use xdrip watchface and display bg values on main screen.)
  9. Finished! You can find your Auth key on /sdcard/freemyband folder of your phone

Notice:

2. xdrip configuration. Connecting to miband

  1. Install xdrip from this link xdrip-miband
  2. If you skipped “Obtaining auth key” phase, go to MiFit settings, and enable band visibility.
  3. Place miband near the phone.
  4. Go to Settings -> Smart watch features -> MiBand and enable option “Use MiBand”.
  5. Normally miband should be automatically found, and you will see a notification with your model name.
  6. If it wasn’t found autmatically, make sure the band visibility option was enabled in MiFit, then disable “Use MiBand” option and repeat step three. You can also enter the mac addres manually (in this case, there no need visibility option enabled).
  7. Now the miband should be connected, but it is required authentification. On MiBand2 and MiBand3, you should approve authentification by touching the miband button. For MiBand4 you don’t need to do anything. Normally auth key should be automatically extracted from the file /sdcard/freemyband which was generated by patched Mi Fit application. But if it was not generated, you should manually enter the key in “Auth key” field and retry everything from step 3
  8. Finally, you should see the message that your miband was succesfully authenticated and now you can control miband via xdrip.

3. xdrip configuration. General settings and installing glucose watchface

3.1. Configuration for MiBand4

If you use a MiBand4, you can receive a glucose readings in two ways.

  1. In standard miband way, using text notifications 
  2. Displaying glucose values on the main band screen with help of custom watchface and specific date modification.

When use a text notification, xdrip would send a message to the miband after every glucose reading. Also there no restrictions in the miband functonality. So you can use an official MiFit application to track activity and music controll.

To display glucose value on the main band screen the xdrip change a date on the band (the date represent the glucose value). Unfortunately, such things as fitness progress, step counters and weather directly related to the date on the tracker. So these features would not work correctly because the date on the band would be changed after every new glucose reading.
The things like music control (not sure regarding alarms and timers) not related to the date, so they should work fine. But official MiFit application continuously corrects the date on miband, which leads to the incorrect glucose values displayed on the band. So at the moment it is not possibe to use miband in such mode with the official apllication.

The option “BG readings as notification” in MiBand settings allow to controll the way you prefer to receive glucose values.

So if you want to see the reading on the main screen and ready to sacify life tracking functionality, you can disable “BG readings as notification” option and press on “Install miband4 watchface” button to install a custom watcface, which will display a bg readings directly on the main watch screen.

Notice: Keep your watch nearby with your phone, while phone transmitting data.

The watchface with required measurement units (mmol or mg/dl ) would be automatically installed. It would use the units from the general xdrip settings.

When the uploading process will be finished, you will see the new watchface on your miband.

Finally to send reading to the see miband you should enable “Send reading” option

3.2. Configuration for MiBand2 and MiBand3

These band version can only receive bg values as notifications. To receive bg reading, you would need to enable “Send reading” and “BG readings as notification” options.

Xdrip miband integration apk changelog

Ver 0.1.4 (16.01.2020)

Ver 0.1.3 (13.01.2020)

Ver 0.1.2 (29.12.2019)

Ver 0.1.1 (28.12.2019)

Ver 0.1 (3.12.2019)

Advertisements

Advertisements