Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

WIP: Enable reading of sensor data #1081

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thePanz
Copy link

@thePanz thePanz commented Apr 24, 2018

Rebase of #894 from @atx

@danielegobbetti
Copy link
Contributor

+1 for me (but I don't have a miband 2 to test)

@thePanz
Copy link
Author

thePanz commented Apr 25, 2018

@danielegobbetti I am working on it, but this is my first project for Android. I am still looking for some hints and tips to how to test/debug on my device... any help? :)

@anony11

This comment has been minimized.

@ligantx
Copy link

ligantx commented Jul 30, 2018

i have mi band 2 and i want to test the raw accelerometer data, but i dont know how to use the submitted code... i downloaded Gadgetbridge app and paired my mi band 2..but there is no Fetch sensor data option in Debug...do i have to do any firmware update?

@thePanz
Copy link
Author

thePanz commented Jul 30, 2018

@jimkaragian this feature is not shipped with the app, you need to compile the source code and run the "self-compiled" app on your phone.
I had no time to continue this Pull-Request, sorry

@ligantx
Copy link

ligantx commented Aug 1, 2018

@thePanz sorry for asking but im totally new to this area..how to compile an apk?
i mean normally there is a make file etc..
now i see there is a gradle folder (and gradle is a build tool right?)...so i download the Gadgetbridge-master file, change the code to your_code for Mi Band 2..and then compile it with gradle? (is there any tutorial or something for this procedure?)
thank you in advance..(i can delete the comment if its considered off-topic)

@thePanz
Copy link
Author

thePanz commented Aug 2, 2018

@jimkaragian about the code: you can just clone my repository :) and yes, graddle is a building tool: I use IntelliJ to compile the code, but had to reset my machine and I don't have a building environment anymore at the moment.

Hope any of the maintainers will help here with the "compiling" questions, it could be cool if such instructions were available in the main repository too, under a how to compile section? @danielegobbetti

@h3ndrik
Copy link

h3ndrik commented Aug 25, 2018

is this also implemented in the mi band 3 firmware?

@thePanz
Copy link
Author

thePanz commented Aug 27, 2018

@h3ndrik I have no clue about the MiBand3. Actually I wasn't even able to test this on my MiBand2 :(

@Epictek
Copy link

Epictek commented Aug 30, 2018

Did some work on parsing the output to XYZ values.

diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/MiBand2Support.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/MiBand2Support.java
index 7773ca4f..85108b45 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/MiBand2Support.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/MiBand2Support.java
@@ -1163,13 +1165,16 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
      * @param value The data bytes
      */
     private void handleSensorData(byte[] value) {
-        String string = "";
-        for (byte b : value) {
-            string = string.concat(String.format(" 0x%4x", b));
-        }
-        LOG.warn("Received sensor data:" + string);
-
-        if ((value.length - 2) % 6 != 0) {
+        int i = 2;
+        if (value.length >= 2 && (value.length - 2) % 6 == 0) {
+            while (i < value.length) {
+                double x = (((value[i] & 255) | ((value[i + 1] & 255) << 8)) << 16) >> 16;
+                double y = (((value[i + 2] & 255) | ((value[i + 3] & 255) << 8)) << 16) >> 16;
+                double z = ((((value[i + 5] & 255) << 8) | (value[i + 4] & 255)) << 16) >> 16;
+                LOG.warn("X: " + x + " Y: " + y +" Z: " + z);
+                i += 6;
+            }
+        } else {
             LOG.warn("Got unexpected sensor data with length: " + value.length);
         }
     }

and here is some example output

2018-08-30 02:27:56.722 17391-17415/nodomain.freeyourgadget.gadgetbridge W/nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: X: -76.0 Y: 200.0 Z: 103.0
2018-08-30 02:27:56.725 17391-17415/nodomain.freeyourgadget.gadgetbridge W/nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: X: -81.0 Y: 199.0 Z: 104.0
2018-08-30 02:27:56.726 17391-17415/nodomain.freeyourgadget.gadgetbridge W/nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: X: -80.0 Y: 200.0 Z: 102.0
2018-08-30 02:27:56.734 17391-17415/nodomain.freeyourgadget.gadgetbridge W/nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: X: -84.0 Y: 199.0 Z: 102.0
2018-08-30 02:27:56.736 17391-17415/nodomain.freeyourgadget.gadgetbridge W/nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: X: -80.0 Y: 200.0 Z: 103.0
2018-08-30 02:27:56.736 17391-17415/nodomain.freeyourgadget.gadgetbridge W/nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: X: -80.0 Y: 195.0 Z: 108.0
2018-08-30 02:27:56.744 17391-17415/nodomain.freeyourgadget.gadgetbridge W/nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: X: -81.0 Y: 199.0 Z: 104.0
2018-08-30 02:27:56.745 17391-17415/nodomain.freeyourgadget.gadgetbridge W/nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: X: -79.0 Y: 200.0 Z: 103.0
2018-08-30 02:27:56.746 17391-17415/nodomain.freeyourgadget.gadgetbridge W/nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: X: -82.0 Y: 201.0 Z: 103.0
2018-08-30 02:27:56.755 17391-17415/nodomain.freeyourgadget.gadgetbridge W/nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: X: -88.0 Y: 200.0 Z: 96.0
2018-08-30 02:27:56.755 17391-17415/nodomain.freeyourgadget.gadgetbridge W/nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: X: -72.0 Y: 195.0 Z: 96.0
2018-08-30 02:27:56.756 17391-17415/nodomain.freeyourgadget.gadgetbridge W/nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: X: -79.0 Y: 198.0 Z: 99.0
2018-08-30 02:27:56.762 17391-17415/nodomain.freeyourgadget.gadgetbridge W/nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: X: -80.0 Y: 194.0 Z: 94.0
2018-08-30 02:27:56.763 17391-17415/nodomain.freeyourgadget.gadgetbridge W/nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: X: -89.0 Y: 184.0 Z: 94.0
2018-08-30 02:27:56.763 17391-17415/nodomain.freeyourgadget.gadgetbridge W/nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: X: -89.0 Y: 187.0 Z: 83.0
2018-08-30 02:27:56.771 17391-17414/nodomain.freeyourgadget.gadgetbridge W/nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: X: -87.0 Y: 188.0 Z: 63.0
2018-08-30 02:27:56.772 17391-17414/nodomain.freeyourgadget.gadgetbridge W/nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support: X: -104.0 Y: 177.0 Z: 60.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants