Android Question BroadCastReceiver & Blood Glucose Data

duneplodder

Active Member
Licensed User
Longtime User
I am using an app to read my blood glucose from a continuous blood glucose meter.
This app can broadcast each new reading which another of the developer's apps can use. All this works well.
I would like though to intercept these readings in a B4A app. I imagine I should be able to do this using the BroadCastReceiver library. However I'm not sure where to start.
Although the software is open source & I can view the code I don't understand Java & cannot see what is happening.

It broadcasts every 5 minutes. Is there a way of listing any intents which are being broadcast, to try & spot the relevant one?

Could anyone advise me as to what I should look for in the existing code?

Sorry to be so vague.
 

tigrot

Well-Known Member
Licensed User
Longtime User
I don't thing that library has anything to do with your problem. Which is the transport for your broadcast? wi-fi or BT? The library you mentioned is about internal brodacast of messages. I understand java a little bit and I'm found of interconnections, since they where my bread in the last 30 years. If you can give more info...
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
I am using an app to read my blood glucose from a continuous blood glucose meter.
This app can broadcast each new reading which another of the developer's apps can use. All this works well.
I would like though to intercept these readings in a B4A app. I imagine I should be able to do this using the BroadCastReceiver library. However I'm not sure where to start.
Although the software is open source & I can view the code I don't understand Java & cannot see what is happening.

It broadcasts every 5 minutes. Is there a way of listing any intents which are being broadcast, to try & spot the relevant one?

Could anyone advise me as to what I should look for in the existing code?

Sorry to be so vague.
I've made several apps for Blood Glucose Monitors, the first question is what is the brand of your BGM, and how does it transmit the data, through USB cable, wireless? wifi/BT?

Regards,
Walter
 
Upvote 0

duneplodder

Active Member
Licensed User
Longtime User
Thank you both.
Sorry, I should have explained more fully.
I'm using a Dexcom G4 CGM. It works well with it's receiver. For anyone with Type 1 Diabetes it is life changing.
I have also built an electronic device which converts the data transmitted from the CGM into Bluetooth. This is a great system designed by an open source developer, Stephen Black, together with an Android App (xDrip) to read & display the data. This also works well. See http://stephenblackwasalreadytaken.github.io/xDrip/

The xDrip app has an option to internally "broadcast" the data. He has another app, called "NightWatch" which can use the data.
What I would like to do is receive this data in a B4A app for my own purposes.

As I said xDrip is open source, so if anyone has the time the code is in Github at the link above. I've downloaded it & viewed it in Android Studio but don't know Java so have been unable to understand what the relevant code is.
 
Upvote 0

duneplodder

Active Member
Licensed User
Longtime User
I have seen the code. It misses some style data so i'm unable to compile...
Yes I noticed that.
In the meantime I've made a little progress, with some help. I now have the relevant strings:

Broadcast.addAction("com.dexdrip.stephenblack.nightwatch.action.NEW_DATA")
Broadcast.addAction("com.eveningoutpost.dexdrip.BgEstimate")

And receive this:
Action=com.eveningoutpost.dexdrip.BgEstimate
Intent=Intent { act=com.eveningoutpost.dexdrip.BgEstimate flg=0x10 (has extras) }

To be honest I'm out of my depth as I've never done anything with Intents but I'll keep reading..
 
Upvote 0

duneplodder

Active Member
Licensed User
Longtime User
I'm having another look at this but I'm afraid I'm struggling. This is an open

source app which does read the broadcast data:
https://github.com/StephenBlackWasAlreadyTaken/NightWatch

This seems to be the main class which deals with received intent:


B4X:
public class IntentService extends android.app.IntentService {
  public static final String ACTION_NEW_DATA =

"com.dexdrip.stephenblack.nightwatch.action.NEW_DATA";

  public IntentService() {
  super("DexDripIntentService");
  setIntentRedelivery(true);
  }

  @Override
  protected void onHandleIntent(Intent intent) {
  if (intent == null)
  return;

  final String action = intent.getAction();

  try {
  if (ACTION_NEW_DATA.equals(action)) {
  final double bgEstimate = intent.getDoubleExtra(Intents.EXTRA_BG_ESTIMATE,

0);
  if (bgEstimate == 0)
  return;

  int battery = intent.getIntExtra(Intents.EXTRA_SENSOR_BATTERY, 0);

  final Bg bg = new Bg();
  bg.direction = intent.getStringExtra(Intents.EXTRA_BG_SLOPE_NAME);
  bg.battery = Integer.toString(battery);
  bg.bgdelta = (intent.getDoubleExtra(Intents.EXTRA_BG_SLOPE, 0) * 1000 * 60 *

5);
  bg.datetime = intent.getLongExtra(Intents.EXTRA_TIMESTAMP, new Date

().getTime());
  bg.sgv = Integer.toString((int) bgEstimate, 10);
  bg.save();
  DataCollectionService.newDataArrived(this, true, bg);
  }
  } finally {
  WakefulBroadcastReceiver.completeWakefulIntent(intent);
  }
  }
}


The data it receives is in a class called Bg defined here:

B4X:
public class Bg extends Model {
  public SharedPreferences prefs;

  @Expose
  @Column(name = "sgv")
  public String sgv;

  @Expose
  @Column(name = "bgdelta")
  public double bgdelta;

  @Expose
  @Column(name = "trend")
  public double trend;

  @Expose
  @Column(name = "direction")
  public String direction;

  @Expose
  @Column(name = "datetime")
  public double datetime;

  @Expose
  @Column(name = "battery")
  public String battery;

  @Expose
  @Column(name = "filtered")
  public double filtered;

  @Expose
  @Column(name = "unfiltered")
  public double unfiltered;


What would this class look like in B4A?

In B4A I have been able to connect & receive the following:
Action=com.eveningoutpost.dexdrip.BgEstimate
Intent=Intent { act=com.eveningoutpost.dexdrip.BgEstimate flg=0x10 (has extras) }

But I'm completely lost as to how to use this..
Any help would be much appreciated.
 
Upvote 0
Top