Android Question Diabetes related Bluetooth BLE app

Discussion in 'Android Questions' started by duneplodder, Jun 11, 2015.

  1. duneplodder

    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..
  2. duneplodder

    duneplodder Active Member Licensed User

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

    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
    Log("Supported= " & manager.BleSupported)
    End If
    End Sub

    Sub Activity_Click
    Log("Searching for devices")
    ToastMessageShow("Searching for Devices..",True)
    End Sub

    Sub ble_DeviceFound (Name As String, MacAddress As String)
    Log(Name & ", " & MacAddress)
    ToastMessageShow("Device Found=" & Name & ", " & 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))

    Log("read: " & c.Uuid)

    End Sub

    Sub BLE_CharacteristicRead (Success As Boolean, Characteristic As BleCharacteristic)

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

    End Sub

    Sub ble_Disconnected
    End Sub

    Sub ble_DiscoveryFinished
    End Sub

    Sub ble_CharacteristicChanged (Characteristic As BleCharacteristic)

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

    End Sub

    is the log it produces.


    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.
    Last edited: Jun 11, 2015
  3. Erel

    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:
    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)
    End Sub
    Devan and Peter Simpson like this.
  4. duneplodder

    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.
  5. duneplodder

    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.
  6. duneplodder

    duneplodder Active Member Licensed User

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

    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..
  7. duneplodder

    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
    CR: true: 00002a28-0000-1000-8000-00805f9b34fb
    String=Software Revision��
    CR: true: 0000ffe1-0000-1000-8000-00805f9b34fb
    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
    CR: true: 00002a50-0000-1000-8000-00805f9b34fb
    CR: true: 00002a01-0000-1000-8000-00805f9b34fb
    CR: true: 00002a23-0000-1000-8000-00805f9b34fb
    CR: true: 00002a00-0000-1000-8000-00805f9b34fb
    CR: true: 00002a24-0000-1000-8000-00805f9b34fb
    String=Model Number��
    CR: true: 00002a04-0000-1000-8000-00805f9b34fb
  8. Erel

    Erel Administrator Staff Member Licensed User

    This is an asynchronous method. The events will later be raised.
    Peter Simpson likes this.
  9. duneplodder

    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.
  10. Cableguy

    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?
  11. duneplodder

    duneplodder Active Member Licensed User

    Hi CableGuy.
    Of course, I'm using a Dexcom G4 Continuous Glucose Monitor.
    That's the UK page, not sure where you are.

    This is the xDrip box & app:
    With a good description here:

    Also have a look at the NightScout Project - wonderful for parents or carers.

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

    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.

  13. duneplodder

    duneplodder Active Member Licensed User

    Hi Devan, thanks, that is what I've been doing.
    Message #7 is my most recent logging output.
  14. walterf25

    walterf25 Well-Known Member 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.

    DonManfred likes this.
  15. duneplodder

    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.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice