Basic BodyBattery code example

I'm trying to make a widget or an app that will query BodyBattery. I have this piece of code that compiles, but never enters the `if (ActivityMonitor has :getBodyBatteryHistory)` even though I'm trying it in the simulator on Venu 2 System 5 preview, with targetApiLevel: 4.1.x and minApiLevel: 4.1.0.beta1.

I'm not sure what permissions are needed (Garmin, it would be nice to be able to know it from the documentation...), so I have these in the manifest:

<iq:permissions>
<iq:uses-permission id="Background"/>
<iq:uses-permission id="PersistedContent"/>
<iq:uses-permission id="Sensor"/>
<iq:uses-permission id="SensorHistory"/>
</iq:permissions>

I have this in my view:

    function onUpdate(dc as Dc) as Void {
    	if (ActivityMonitor has :getBodyBatteryHistory) { // this is always false
    		var bbIter = ActivityMonitor.getBodyBatteryHistory();
    		if (bbIter != null) {
    			var bbData = bbIter.next();
    			if (bbData != null) {
    				System.println("BB: " + bbData);
    			}
    		}
    	}
        // Call the parent onUpdate function to redraw the layout
        View.onUpdate(dc);
    }

(Garmin!!!!!!!!!!!!! Why there isn't Monkey C in the code languages????? Why My formatted code is displayed like this in the editor?????)


Any idea what am I doing wrong?

  • 1. yes, there is "valid symbol" for :getBodyBatteryHistory

    2. but unfortunately, on sim ActivityMonitor return doesn't have :getBodyBatteryHistory - bug

    3. I have f6p - no system 5 - so I I can't test if it run on device but if you have device with system 5 you can do it

  • So the simulator useless for developing System 5 features?

    So the only thing I can do is to side-load on my son's FR245 that already has 9.0. But then it's impossible to debug. Certainly not the best way to develop my 1st widget/app :(

  • 1. you don't need to debug because your code looks good

    2. you can see  System.println log on your watch but the simplest way is to show data directly using. dc.drawtext(), so

    - make member in view mBBdata

    - use mBBdata instead of bbData

    - and remember that bbData is class

    Class: Toybox.ActivityMonitor.BodyBatteryData

    Inherits:
    Toybox.Lang.Object show all

    Overview

    A class to store body battery information

    Since:

    API Level 3.3.0

    Instance Member Summary collapse

    • bodyBattery as Lang.Number

      Value for the body battery in points.

    • when as Time.Moment

      Timestamp when the body battery was measured.

    so drawText(... mBBdata.bodyBattery)

  • The 4.1.0-beta1 SDK is about 5 months old, and as it's a beta, and some things don't work.  Personally, I'm not going to worry about things like body battery until there is a beta2 or 4.1.1 release, as I'm sure there have been fixes over the 5 months.

    If you want to debug on a real device like your son's 245, you can add println calls to your code, and create an app specific log file to see what's going on. See https://forums.garmin.com/developer/connect-iq/w/wiki/4/new-developer-faq#debugging

  • do you know what permission is needed to be able to reach the BodyBattery and Stress data?

  • I think no permission needed but maybe SensorHistory.

    Do you have System 5 watch?

  • You shouldn't need the permissions you listed.  If you need a permission, the sim will let you know.  Things like the background permission can cause issues if you don't have things annotated for the background and the app is greater than 28k.

  • Do you have System 5 watch?

    His son's 245 with the 9.00 FW is system 5.

  • Still doesn't work. I mean it runs now both in the simulator (FR245 3.2.0) and on real device (FR245 3.3.1), but even in the real device it doesn't enter the if:

    if (ActivityMonitor has :getBodyBatteryHistory) {
        System.println("has getBodyBatteryHistory");
    }

    Does this mean this is a bug in 4.1.0-beta1 or that 3.3.1 on FR245 doesn't implement the bodyBattery?

    I had to compile with sdk 4.1.0-beta1, because when I tried with 4.0.10 then I got compilation errors:
    BUILD: ERROR: fr245: MyApp/source/GlancePage.mc:37: Undefined symbol "bodyBattery" detected.
    on this line:

    mBodyBatteryVal = bodyBatteryData.bodyBattery;

    this is the declaration of bodyBatteryData:

    bodyBatteryData = ... as ActivityMonitor.BodyBatteryData

  • You want to build for a System5 preview device with 4.1.0-beta1 to test  Try the f6pro system 5 preview.  And use "has" to check if what you're using is available.

    Again, I'm waiting for a 4.1.0-beta2 or a 4.1.1 SDK to do much as 4.1.0-beta1 is pretty old right now.