From ff4aa2a14260a26f802fa36cb0cb58626892074f Mon Sep 17 00:00:00 2001 From: Jochen Scheib Date: Sat, 1 Jul 2017 15:02:02 +0200 Subject: [PATCH] Bugfix: Wrong time. Magic Bytes contain timestamp --- .../core/bluetooth/BluetoothMedisanaBS444.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMedisanaBS444.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMedisanaBS444.java index 0a73cba3..fc75a7a2 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMedisanaBS444.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMedisanaBS444.java @@ -91,7 +91,16 @@ public class BluetoothMedisanaBS444 extends BluetoothCommunication { break; case 3: // send magic number to receive weight data - byte[] magicBytes = new byte[]{(byte)0x02, (byte)0x7B, (byte)0x7B, (byte)0xF6, (byte)0x0D}; // 02:7b:7b:f6:0d + Date date = new Date(); + long unix_timestamp = date.getTime() - 1262304000; // -40 years because unix time starts in year 1970 + + byte[] magicBytes = new byte[5]; + magicBytes[0] = (byte)0x02; + for (int i = 4; i >= 1; i--) { + magicBytes[i] = (byte)(unix_timestamp & 0xFF); + unix_timestamp >>= 8; + } + //byte[] magicBytes = new byte[]{(byte)0x02, (byte)0x7B, (byte)0x7B, (byte)0xF6, (byte)0x0D}; // 02:7b:7b:f6:0d writeBytes(WEIGHT_MEASUREMENT_SERVICE, CMD_MEASUREMENT_CHARACTERISTIC, magicBytes); break;