The Protocol Description
seems to do a good job of explaining the format.
To take the example hex numbers in the Manufacturer data
in the question:
[01, // version
B7, // Flag value the same as documentation so it will be the same fields
0A, 01, // Temperature. Big endian so 2561 which needs dividing by 100 to get 25.61
2C, // Humidity. 2c hex is 44 decimal. So 44%
0D, FA, // Movement. Status is "not moving" and 3578 movement count
C7, // Angle. Device pitch (c7) = -57.
00, AC, // Angle. Device Roll (00AC) = 172
6B] // Battery value 3070mv
To do this with the code should be the same as the question you linked to with the exception the data is in Endian.big
format which is the default setting. So for example:
import 'dart:typed_data';
var manufacturerData = Uint8List.fromList([0x01, 0xB7, 0x0A, 0x01, 0x2C, 0x0D, 0xFA, 0xC7, 0x00, 0xAC, 0x6B]);
var flags = ByteData.sublistView(manufacturerData, 1).getUint8(0);
/*
0 – Temperature value presence
1 – Humidity value presence
2 – Magnetic sensor presence
3 – Magnetic sensor state (1 magnetic field is detected/0 magnetic field is not detected) Valid value is present only if bit 2 flag is set.
4 – Movement sensor counter
5 – Movement sensor angle
6 – Low Battery indication (if set to 1 low battery voltage detected)
7 – Battery voltage value presence
*/
var flagTemperature = flags >> 0 & 1;
var flagHumidity = flags >> 1 & 1;
var flagMagPresence = flags >> 2 & 1;
var flagMagState = flags >> 3 & 1;
var flagMoveCount = flags >> 4 & 1;
var flagMoveAngle = flags >> 5 & 1;
var flagLowBatt = flags >> 6 & 1;
var flagBattery = flags >> 7 & 1;
var temperature = ByteData.sublistView(manufacturerData, 2, 4);
var humidity = ByteData.sublistView(manufacturerData, 4, 5);
var movement = ByteData.sublistView(manufacturerData, 5, 7);
var movementStatus = movement.getUint16(0) >> 15 & 1;
var movementCount = movement.getUint16(0) & 0x7fff;
var devicePitch = ByteData.sublistView(manufacturerData, 7, 8);
var deviceRoll = ByteData.sublistView(manufacturerData, 8, 10);
var battery = ByteData.sublistView(manufacturerData, 10, 11);
main() {
print("Temperature Value presence: " + flagTemperature.toString());
print("Humidity Value presence: " + flagHumidity.toString());
print("Magnetic Value presence: " + flagMagPresence.toString());
print("Magnetic State: " + flagMagState.toString());
print("Move Sensor: " + flagMoveCount.toString());
print("Move Angle: " + flagMoveAngle.toString());
print("Low Battery: " + flagLowBatt.toString());
print("Battery Value Presence: " + flagBattery.toString());
print("Temperature: " + (temperature.getUint16(0) / 100).toString());
print("Humidity: " + humidity.getUint8(0).toString());
print("Movement Status: " + movementStatus.toString());
print("Movement count: " + movementCount.toString());
print("Device Pitch: " + devicePitch.getInt8(0).toString());
print("Device Roll: " + deviceRoll.getInt16(0).toString());
print("Battery: " + (2000 + (battery.getUint8(0) * 10)).toString());
}
Which prints to the console:
Temperature Value presence: 1
Humidity Value presence: 1
Magnetic Value presence: 1
Magnetic State: 0
Move Sensor: 1
Move Angle: 1
Low Battery: 0
Battery Value Presence: 1
Temperature: 25.61
Humidity: 44
Movement Status: 0
Movement count: 3578
Device Pitch: -57
Device Roll: 172
Battery: 3070