Android Question Diabetes related Bluetooth BLE app

duneplodder

Active Member
Licensed User
First some background information. I have type 1 diabetes and I use something called a Continuous Blood Glucose Monitor. I wear a sensor with a transmitter & my blood sugar readings are continuous visible on a receiver which is amazing for me.

An open source developer has designed an electronic device which converts the data from the transmitter into BLE Bluetooth & written an app in java for Android which reads this data from a mobile phone. Again brilliant - I've built the device, known as xDrip & it works well.

What I would like to do, for my own satisfaction, is write a B4A app which reads the data. I have tested an app from Google Play called "BLE Tool" & it can see the data I want - see screenshot.
BLE Tool Screen.jpg


It is the 131968 portion I am interested in.

Note that the device is one way, transmitting every 5 minutes.

I'll continue in a new message so it doesn't get too big..
 

duneplodder

Active Member
Licensed User
I have done a bit of testing using code posted by other people & the BleExtEx library, thank you.

B4X:
Sub Process_Globals
  Dim manager As BleManager
  Private cs As List
End Sub

Sub Globals
  'These global variables will be redeclared each time the activity is created.
  'These variables can only be accessed from this module.
Dim i As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
  If FirstTime Then
  manager.Initialize("ble")
  Log("Supported= " & manager.BleSupported)
  End If
End Sub

Sub Activity_Click
  Log("Searching for devices")
  ToastMessageShow("Searching for Devices..",True)
  manager.Scan(100000, Null)
End Sub

Sub ble_DeviceFound (Name As String, MacAddress As String)
  Log(Name & ", " & MacAddress)
  ToastMessageShow("Device Found=" & Name & ", " & MacAddress,True)
  manager.Connect(MacAddress, True)

End Sub

Sub BLE_Connected (Services As Map)
Dim n As Int,s As BleService,cr As String,c As BleCharacteristic

Log ("AanzahlServices size = " & Services.Size)

For n=0 To 3
   s = Services.GetValueAt(n)
   Log("Service[" & n & "]: " & Services.GetKeyAt(n))
Next

c=s.GetCharacteristics.GetValueAt(0)
Log("read: " & c.Uuid)
manager.ReadCharacteristic(c)

End Sub

Sub BLE_CharacteristicRead (Success As Boolean, Characteristic As BleCharacteristic)

Log("CR: " & Success & ": " & Characteristic.Uuid)

End Sub

Sub ble_Disconnected
  Log("Disconnected")
End Sub

Sub ble_DiscoveryFinished
  Log("DiscoveryFinished")
End Sub


Sub ble_CharacteristicChanged (Characteristic As BleCharacteristic)

Log("In Changed. UUID=" & Characteristic.Uuid)

End Sub
/Code

This is the log it produces.

[ATTACH=full]34797[/ATTACH]

So I feel as though I'm close, but unfortunately I don't really understand the terminology & I'm not sure what the next step is - I think I want to log data from Service[3).
Any pointers would be much appreciated.
 

Attachments

Last edited:

Erel

Administrator
Staff member
Licensed User
Please use [code]code here...[/code] tags when posting code.

Your current code only reads the first characteristic of the last service.

You need to read all of the characteristics from all the services to find the one you are interested in.

Something like:
B4X:
Sub BLE_Connected (Services As Map)
 For Each ser As BleService In Services.Values
  Log("Service UUID: " & ser.Uuid)
  For Each cr As BleCharacteristic In ser.GetCharacteristics.Values
    Manager.ReadCharacteristic (cr)
  Next
 Next
End Sub
 

duneplodder

Active Member
Licensed User
Thank you Erel. I'll give that a try.
I've edited the code as you suggest - sorry, I'd forgotten how to do that.
 

duneplodder

Active Member
Licensed User
My log now looks like this:

Searching for devices
BOLUTEK, 00:15:83:00:2F:5B
inlib onConnectionStateChange 0 2
Discovering services.
AanzahlServices size = 4
Service UUID: 00001800-0000-1000-8000-00805f9b34fb
Service UUID: 00001801-0000-1000-8000-00805f9b34fb
Service UUID: 0000180a-0000-1000-8000-00805f9b34fb
Service UUID: 0000ffe0-0000-1000-8000-00805f9b34fb
CR: true: 00002a00-0000-1000-8000-00805f9b34fb

Unfortunately I don't understand enough to know what my next step should be...
The device has an HM10 bluetooth board in case this helps.
 

duneplodder

Active Member
Licensed User
in the loop Erel suggested:
For Each cr As BleCharacteristic In ser.GetCharacteristics.Values
manager.ReadCharacteristic (cr)
Next

I would have thought that each "manager.readcharacteristic(cr)" would trigger a "BLE_CharacteristicRead" but this doesn't seem to happen until after the loop has been completed.
Grasping at straws here..
 

duneplodder

Active Member
Licensed User
Strangely if I single step through using the debugger it does seem to trigger the BLE_CharacteristicReads - I get a lot more data:

CR: true: 00002a2a-0000-1000-8000-00805f9b34fb
String=���experimental
CR: true: 00002a28-0000-1000-8000-00805f9b34fb
String=Software Revision��
CR: true: 0000ffe1-0000-1000-8000-00805f9b34fb
String=
CR: true: 00002a29-0000-1000-8000-00805f9b34fb
String=Manufacturer Name��
CR: true: 00002a27-0000-1000-8000-00805f9b34fb
String=Hardware Revision��
CR: true: 00002a26-0000-1000-8000-00805f9b34fb
String=Firmware Revision��
CR: true: 00002a25-0000-1000-8000-00805f9b34fb
String=Serial Number��
CR: true: 00002a02-0000-1000-8000-00805f9b34fb
String=��
CR: true: 00002a50-0000-1000-8000-00805f9b34fb
String=
������
CR: true: 00002a01-0000-1000-8000-00805f9b34fb
String=����
CR: true: 00002a23-0000-1000-8000-00805f9b34fb
String=[/���������
CR: true: 00002a00-0000-1000-8000-00805f9b34fb
String=BOLUTEK
CR: true: 00002a24-0000-1000-8000-00805f9b34fb
String=Model Number��
CR: true: 00002a04-0000-1000-8000-00805f9b34fb
String=P����������
 

duneplodder

Active Member
Licensed User
Thank you.

I see them if I either step through in debug mode, or insert a short pause in your suggested loop, otherwise only once.
 

Cableguy

Expert
Licensed User
Since I have a daughter with melitus too, I would like to know a bit more about your continuous reader and ble interface. Do you have any links I can look in to?
 

duneplodder

Active Member
Licensed User
Hi CableGuy.
Of course, I'm using a Dexcom G4 Continuous Glucose Monitor.

http://www.dexcom.com/en-gb
That's the UK page, not sure where you are.

This is the xDrip box & app:
http://stephenblackwasalreadytaken.github.io/xDrip/
With a good description here:
http://circles-of-blue.winchcombe.o...-guide-to-building-a-dexdrip-wearenotwaiting/

Also have a look at the NightScout Project - wonderful for parents or carers.
http://www.nightscout.info/

The xDrip & NightScout are both developed by volunteers & the software is open source. Just wish I understood Java...
 

Devan

Member
Licensed User
Hi dune plodder,
Most of time I use "Log()" messages to understand the flow & data I get. From there I try to modify the code to get the result. Maybe u should use log messages as much as u like to understand your code flow.

Tq
 

walterf25

Expert
Licensed User
Wow, this is really great, I work for a company called Medtronic, which builds insulin pumps for diabetic people as well, I had no idea projects like this existed, we are barely trying to build an app for our pumps. This is Awesome.

Walter
 

duneplodder

Active Member
Licensed User
So far I haven't had any success with this, but I have discovered that the blood glucose readings are being broadcast from the 3rd party app, called xDrip, which I use.
This would be a better option if I can receive the data. I've started another thread on the subject.
 
Top