oliexdev / openScale

Open-source weight and body metrics tracker, with support for Bluetooth scales
GNU General Public License v3.0
1.72k stars 297 forks source link

Beurer BF 600 not supported. #219

Closed riadhrom closed 3 years ago

riadhrom commented 6 years ago

Hi everyone,

Could you help me about the connection of Beurer BF 600.

screenshot_20180308-143806

Thank you.

erijo commented 6 years ago

@riadhrom: why did you close this issue? Are you not interested in support for that scale any more? It could potentially be a simple task to add the needed support, but we would need someone that can test it.

riadhrom commented 6 years ago

@erijo : Hi erijo. Of course, I'm interested in support for that scale but I'm novice in computer programming so I don't have any idea about how I do it. I read the post and it's a chineese for me :( But I can test your code if you want :)

erijo commented 6 years ago

Please try the dev version and let me know how it goes: https://github.com/oliexdev/openScale/releases/tag/travis-dev-build

riadhrom commented 6 years ago

Thank you very much. The connection is established but the data is empty and no records.

screenshot_20180410-174210

erijo commented 6 years ago

Please reset the scale and then connect with the app again. Do you then see a message requesting you to step on the scale?

riadhrom commented 6 years ago

I reset the scale and I saw a message requesting me to step on it. I put the time the year the month the day and my body's informations. Then a code pin is displayed. I connected the scale and it's the same problem. I repeated the operation three times.

erijo commented 6 years ago

I think we need the bluetooth trafic log to figure this out. Can you perform part 1 from https://github.com/oliexdev/openScale/wiki/How-to-reverse-engineer-a-Bluetooth-4.x-scale and post the log here?

Dododappere commented 6 years ago

The BF600 is different than the other Beurer scales. This one is based on the standard bluetooth profiles for User, Weight and BodyComposition. So you have to implement those to make it work.

See: User Data Service Weight Scale Service Body Composition Service

erijo commented 6 years ago

@riadhrom : will you be able to provide the bluetooth logs? Otherwise I don't think we can do much about this...

dglozano commented 6 years ago

Hello, I am Diego from Argentina. I am trying build an app that connects to a BF600 for a project at University, but I am struggling a lot to get the weight data from the scale.

Looking at the logs (I am attaching 3 different logs, all of them with data that traveled between the scale and the Beurer App) it seems that you need to set the indicate flag in the following characteristics: -Weight Measurement -Body Composition Measurement -User Control Point And the notification flag in: -Database change Increment -Current Time

There are some other custom services and characteristics that I don't know what they are for.

Afterwards, it creates an user if no user exists already. If an user exists, you can write to the User Control Point a Consen operation with the user index and the user pin (a number that you can see in the scale for each user)

I have tried to do that but It is not working at all. It is my very first attempt to develop something connecting to a BLE device so I am very lost... I have tried to follow the tutorial in the Android API and I tried to get just the Weight Measurement for an already created user but I couldn't :(

I would be very grateful if any of you could help me, and if I can get it working I will be able to contribute adding support for the BF600 for this project too.

btsnoop_hci4-5-4396PIN-CREACION-CONEXION.log btsnoop_hciLAST7277.log btsnoop_hci75.log

(if you need more logs or anything let me know)

erijo commented 6 years ago

If you run openScale, enable debug log in settings, about and then go scan for the scale in settings, Bluetooth and once found click on it. Do you then get that openScale can connect to it and discover all services?

Please attach the log here afterwards.

erijo commented 6 years ago

Any updates on this @dglozano?

dglozano commented 6 years ago

Erijo, sorry I have been very busy with uni (the semester ends next week here). After that I will continue trying with this and I will upload the log @erijo

DM5KA commented 6 years ago

Hi @erijo , here's a log of the BF600.. OpenScale OpenScale grabs extended Data and then stops scanning... a real connection is not possible.

openScale_2018-08-12_10-07.txt

regads :)

erijo commented 5 years ago

Long time to no action, but I've created a dev version with some initial code that might be able to set the time on the scale. Can someone please test this version and attach a log here?

@inkiiin, @dglozano, @riadhrom?

erijo commented 5 years ago

Anyone willing to try the dev version? We can't bring this forward unless someone is willing to help run the dev version and post logs.

heikoschwarz commented 5 years ago

@erijo I've tested your version on my BF600, here's the log: openScale_2018-12-29_23-26.txt

fabianpie commented 5 years ago

Hi @Dododappere I haven't bought and tried a Beurer BF600 yet. Could you confirm it implements the standard profiles ? Have you developed an app and you are sure ? Thanks, Fabian

oliexdev commented 5 years ago

first skeleton by @erijo for reference

/* Copyright (C) 2018 Erik Johansson <erik@ejohansson.se>
 *
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>
 */

package com.health.openscale.core.bluetooth;

import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.content.Context;

import com.health.openscale.core.utils.Converters;

import java.util.Calendar;

public class BluetoothBf600 extends BluetoothCommunication {

    public BluetoothBf600(Context context) {
        super(context);
    }

    @Override
    public String driverName() {
        return "BF600";
    }

    @Override
    protected boolean nextInitCmd(int stateNr) {
        switch (stateNr) {
            case 0:
                setIndicationOn(BluetoothGattUuid.SERVICE_WEIGHT_SCALE,
                        BluetoothGattUuid.CHARACTERISTIC_WEIGHT_MEASUREMENT,
                        BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION);
                break;
            case 1:
                setIndicationOn(BluetoothGattUuid.SERVICE_BODY_COMPOSITION,
                        BluetoothGattUuid.CHARACTERISTIC_BODY_COMPOSITION_MEASUREMENT,
                        BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION);
                break;
            case 2:
                byte[] time = new byte[10];
                Calendar cal = Calendar.getInstance();

                Converters.toInt16Le(time, 0, cal.get(Calendar.YEAR));
                time[2] = (byte) (cal.get(Calendar.MONTH) + 1);
                time[3] = (byte) cal.get(Calendar.DAY_OF_MONTH);
                time[4] = (byte) cal.get(Calendar.HOUR_OF_DAY);
                time[5] = (byte) cal.get(Calendar.MINUTE);
                time[6] = (byte) cal.get(Calendar.SECOND);
                time[7] = 0; // day of week (0 = unknown)
                time[8] = 0; // fractions of a second
                time[9] = 0; // adjust reason

                writeBytes(BluetoothGattUuid.SERVICE_CURRENT_TIME,
                        BluetoothGattUuid.CHARACTERISTIC_CURRENT_TIME, time);
                break;
            default:
                return false;
        }

        return true;
    }

    @Override
    protected boolean nextBluetoothCmd(int stateNr) {
        return false;
    }

    @Override
    protected boolean nextCleanUpCmd(int stateNr) {
        return false;
    }

    @Override
    public void onBluetoothDataChange(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic gattCharacteristic) {

    }
}
Dododappere commented 5 years ago

https://github.com/weliem/beurer-BF600-BF850/blob/master/app/src/main/java/com/welie/bf600/BluetoothHandler.java

oliexdev commented 5 years ago

@Dododappere thanks for the link

oliexdev commented 5 years ago

please try out the latest blessed-android branch version at https://github.com/oliexdev/openScale/releases/tag/travis-dev_blessed-android-build I implemented a first version based on the source-code by @weliem (many thanks to him!) As I don't own this scale, I can't test it, so please test it while the debug log is on (enable it under settings-about)

mohdumarj commented 5 years ago

the above file is not available by @weliem ... :(

shurakr commented 5 years ago

@oliexdev the above file is not available. What can I do to help the project, and to add support for these scale?

shurakr commented 5 years ago

I found out the description of the bf600 and bf850 protocol

bleapi.zip

oliexdev commented 5 years ago

@shurakr I don't own this scale without testing the code it will be hard to support it. We need someone to own this scale and to to test the source code. I implemented already some untested version. Do you have programmer skills?

shurakr commented 5 years ago

Yes, i have

oliexdev commented 5 years ago

Then you could test the implementation, you have only uncomment the line if (name.startsWith("BEURER BF600".toLowerCase(Locale.US)) in the BluetoothFactory.java file.

shurakr commented 5 years ago

I do not have a development environment, please build a test version.

oliexdev commented 5 years ago

@shurakr I thought you have programmer skills? If not it will be difficult.

shurakr commented 5 years ago

experience is, but I'm not programming for android.

shackra commented 4 years ago

got this scale lol. Uh, how can I help?

EDIT: ah, I see https://github.com/oliexdev/openScale/wiki/How-to-reverse-engineer-a-Bluetooth-4.x-scale

EDIT 2: on the dev version of OpenScale the BF600 shows as not supported, maybe the developer changed this back after lack of response from owners?

schoeller commented 4 years ago

Then you could test the implementation, you have only uncomment the line if (name.startsWith("BEURER BF600".toLowerCase(Locale.US)) in the BluetoothFactory.java file.

Dear all,

thanks for all the work. I am running LineageOS 10. After uncommenting the lines in BluetoothFactory.java I compiled using

./gradlew compileDebugSources
./gradlew installDebug

copied the openScale-2.3.2-debug.apk onto my phone, installed, executed and connected to my BF600 scale. This is the error output I have received:

Build version: 2.3.2 
Build date: 1981-01-01 01:01:02 
Current date: 2020-11-09 10:04:54 
Device: Motorola moto g(7) 
OS version: Android 10 (SDK 29) 

Stack trace:  
java.lang.IllegalArgumentException: ID does not reference a View inside this Activity
    at android.app.Activity.requireViewById(Activity.java:3237)
    at androidx.core.app.ActivityCompat.requireViewById(ActivityCompat.java:363)
    at androidx.navigation.Navigation.findNavController(Navigation.java:58)
    at com.health.openscale.gui.preferences.BluetoothSettingsFragment$BluetoothDeviceView.onClick(BluetoothSettingsFragment.java:365)
    at android.view.View.performClick(View.java:7259)
    at android.view.View.performClickInternal(View.java:7236)
    at android.view.View.access$3600(View.java:801)
    at android.view.View$PerformClick.run(View.java:27892)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7356)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:491)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:940)

I would be glad to assist further with my limited capabilites.

Kind regards

Sebastian

krisjans commented 3 years ago

@oliexdev

Then you could test the implementation, you have only uncomment the line if (name.startsWith("BEURER BF600".toLowerCase(Locale.US)) in the BluetoothFactory.java file.

I uncommented the code block thats add BF600 support and here is application log I got: openScale_2021-07-08_12-00.txt

Something went wrong with user creation: 2021-07-08 12:36:24.124 Error [2] BluetoothStandardWeightProfile: Not authorized 2021-07-08 12:36:25.595 Debug [2] BluetoothStandardWeightProfile: Created user 13

Another log after I did factory reset on scale: openScale_2021-07-08_12-34.txt

krisjans commented 3 years ago

@oliexdev I managed to store user config from app to Beurer BF600 scale and read weight and body composition measurements. Please take a look at pull request: https://github.com/oliexdev/openScale/pull/753

krisjans commented 3 years ago

This is hci log when Beurer "Health manager" connects to scale BF600 (factory reset has been executed on the scale) for the first time: btsnoop_hci.log. @jensMF , https://github.com/oliexdev/openScale/pull/735

krisjans commented 3 years ago

Anyone wiling to test my latest support for BF600? Pinging people who tested BF600 before: @schoeller @shurakr @heikoschwarz @inkiiin @dglozano @riadhrom ?

This is my private build of #753 : openScale-2.3.5-debug.zip:

krisjans commented 3 years ago

I made some more progress: added existing scale user selection (and pin/consent code dialog). If anyone interested to test - this is updated build of #753: openScale-2.3.5-debug_ui_change.zip

UI changes works only on BF600. Since I have no BF105 I did not update it's support code right now (@jensMF maybe you could check my UI solution and re-use it for BF105? It seems that some-kind of Beurer middle-layer class will be needed to re-use Beurer specific code for BF600, BF850, BF950 and BF105.)

P.S. You don't need factory-reset your scale to try this apk. P.S.2. However - if you performed factory reset on scale, then you must remove your scale from paired devices in phone's Bluetooth settings.

shackra commented 3 years ago

Do I need to factory reset my scale before pairing it with this APK?

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ El jueves, 22 de julio de 2021 a las 08:31, Krišjāns Bluķis @.***> escribió:

I made some more progress: added existing scale user selection (and pin/consent code dialog). If anyone interested to test - this is updated build of #753: openScale-2.3.5-debug_ui_change.zip

UI changes works only on BF600. Since I have no BF105 I did not update it's support code right now @.***MF](https://github.com/jensMF) maybe you could check my UI solution and re-use it for BF105? It seems that some-kind of Beurer middle-layer class will be needed to re-use Beurer specific code for BF600, BF850, BF950 and BF105.)

https://user-images.githubusercontent.com/1708359/126653146-f58963fe-d324-477f-899a-58ec3253b2fd.png https://user-images.githubusercontent.com/1708359/126653787-aec90275-a261-4b23-8eac-b425dab861da.png https://user-images.githubusercontent.com/1708359/126653808-fb886185-c354-4069-8a1d-f81e1978b418.png

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

krisjans commented 3 years ago

Do I need to factory reset my scale before pairing it with this APK?

@shackra : No, factory reset is not needed. You should be able to connect to BF600 and either use existing user or create a new one.

shackra commented 3 years ago

I was able to connect with my BF600 and use the same user on the scale, I will weight myself this Friday

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ El jueves, 22 de julio de 2021 a las 13:06, Krišjāns Bluķis @.***> escribió:

Do I need to factory reset my scale before pairing it with this APK?

@.***(https://github.com/shackra) : No, factory reset is not needed. You should be able to connect to BF600 and either use existing user or create a new one.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

shackra commented 3 years ago

weighted myself, and for my surprise, things went smooth, like using the Beurer's HealthManager but 1000 times better. I'll manually move my data from there to OpenScale. Looking forward for its next release!

shackra commented 3 years ago

oh, btw, I noticed that the bone weight is not getting registered.

I see the BMI getting recorded on the app but I don't see it exported in the CSV, I do have these numbers from HealthManager in my exported file

krisjans commented 3 years ago

oh, btw, I noticed that the bone weight is not getting registered.

I see the BMI getting recorded on the app but I don't see it exported in the CSV, I do have these numbers from HealthManager in my exported file

BF600 scale does not provide bone-mass neither in weight or body composition packet. But it does transmit body "impedance", fat %, water mass, soft-lean-mass, muscle mass, fat-free-mass - therefore I think bone mass could be calculated from those. I see that for other scales bone-mass is often calculated from other measurements (total weight, impedance, fat % and others). @shackra could you check your exported data from HealthManager and see if your bone mass could be calculated from other provided values?

shackra commented 3 years ago

oh, btw, I noticed that the bone weight is not getting registered. I see the BMI getting recorded on the app but I don't see it exported in the CSV, I do have these numbers from HealthManager in my exported file

BF600 scale does not provide bone-mass neither in weight or body composition packet. But it does transmit body "impedance", fat %, water mass, soft-lean-mass, muscle mass, fat-free-mass - therefore I think bone mass could be calculated from those. I see that for other scales bone-mass is often calculated from other measurements (total weight, impedance, fat % and others). @shackra could you check your exported data from HealthManager and see if your bone mass could be calculated from other provided values?

my exported file only provides IBM, % of muscle mass, % of water, % of body fat and the bone density which is display in kg

krisjans commented 3 years ago

@shackra Maybe you would like to help to figure out formula to calculate bone-mass from other measurments? If you do, then grab this debug version: openScale-2.3.5-debug-bone-mass-quest.zip This version will dump all measurements provided by scale in debug log. If you already know your bone mass, then maybe you can figure out how to calculate it from other values (for example subtract all other known weight values from total body mass)? Debug log example:

D/BluetoothStandardWeightProfile: ################################################## Step Nr 15
D/BluetoothStandardWeightProfile: handleWeightMeasurement -------------------------------------------- value: 0E F2 2F E5 07 07 17 15 21 1F 02 D4 00 A4 06
D/BluetoothStandardWeightProfile: handleWeightMeasurement -------------------------------------------- flags: 0x0e 
D/BluetoothStandardWeightProfile: handleWeightMeasurement -------------------------------------------- Time: Fri Jul 23 21:33:31 GMT+03:00 2021
D/BluetoothStandardWeightProfile: handleWeightMeasurement -------------------------------------------- User id: 1, scale user index: 2
D/BluetoothStandardWeightProfile: handleWeightMeasurement -------------------------------------------- BMI: 21.2
D/BluetoothStandardWeightProfile: handleWeightMeasurement -------------------------------------------- heightInMeters: 1.7
D/BluetoothStandardWeightProfile: Got weight: 61.37
D/BluetoothStandardWeightProfile: ################################################## Step Nr 15
D/BluetoothStandardWeightProfile: handleBodyCompositionMeasurement ---------------------------------- value: 98 03 B6 00 13 18 A3 01 30 25 F4 1A 79 0B
D/BluetoothStandardWeightProfile: handleBodyCompositionMeasurement ---------------------------------- flags: 0x0398
D/BluetoothStandardWeightProfile: handleBodyCompositionMeasurement ---------------------------------- bodyFatPercentage: 18.2
D/BluetoothStandardWeightProfile: handleBodyCompositionMeasurement ---------------------------------- bmrInJoules: 6163 bmrInKcal: 1472
D/BluetoothStandardWeightProfile: handleBodyCompositionMeasurement ---------------------------------- musclePercentage: 41.9
D/BluetoothStandardWeightProfile: handleBodyCompositionMeasurement ---------------------------------- softLeanMass: 47.6
D/BluetoothStandardWeightProfile: handleBodyCompositionMeasurement ---------------------------------- bodyWaterMass: 34.5
D/BluetoothStandardWeightProfile: handleBodyCompositionMeasurement ---------------------------------- impedance: 293.7
D/BluetoothStandardWeightProfile: Got body composition: 98 03 B6 00 13 18 A3 01 30 25 F4 1A 79 0B
D/OpenScale: Added measurement: ID: 0, USER_ID: 1, DATE_TIME: Fri Jul 23 21:33:31 GMT+03:00 2021, WEIGHT: 61.37, FAT: 18.20, WATER: 34.50, MUSCLE: 41.90, LBM: 47.60, WAIST: 0.00, HIP: 0.00, BONE: 0.00, CHEST: 0.00, THIGH: 0.00, ARM: 0.00, NECK: 0.00, CALIPER1: 0.00, CALIPER2: 0.00, CALIPER3: 0.00, COMMENT: 
D/BluetoothStandardWeightProfile: ################################################## Step Nr 15
shackra commented 3 years ago

I rather give you my logs, lol. I'm awful at math.

my bone weight has been always between 3.2 KG, 3.3 KG and 3.4 KG, I don't discard that is still fluctuating around those numbers (probably I'm at 3.3 KG right now)

openScale_2021-07-23_13-23.txt

dror3go commented 3 years ago

Hey @krisjans - many thanks for the progress you're making here :clap: I have BF 950, and I would like to try out your latest version. Any chance you can create a relevant APK?

It seems that some-kind of Beurer middle-layer class will be needed to re-use Beurer specific code for BF600, BF850, BF950 and BF105.

Should it be "Bluetooth standard protocol"-specific instead of "Beurer"-specific?

krisjans commented 3 years ago

A bit more progress:

If anyone interested to test - this is updated build of #753: openScale-2.3.5-debug_bf600_bf850_bf950.zip

krisjans commented 3 years ago

It seems that some-kind of Beurer middle-layer class will be needed to re-use Beurer specific code for BF600, BF850, BF950 and BF105.

Should it be "Bluetooth standard protocol"-specific instead of "Beurer"-specific?

It should be in between "Bluetooth standard protocol" and specific Beurer scale classes (see this comment in pull-request). BluetoothStandardWeightProfile -> BluetoothStandardWeightProfileBeurer -> BluetoothBeurerBF105 BluetoothStandardWeightProfile -> BluetoothStandardWeightProfileBeurer -> BluetoothBeurerBF600 BluetoothStandardWeightProfile -> BluetoothStandardWeightProfileBeurer -> BluetoothBeurerBF850 BluetoothStandardWeightProfile -> BluetoothStandardWeightProfileBeurer -> BluetoothBeurerBF950