我正在使用flutter_blue插件來發現信標和傳感器。就我而言,我使用的是 Teltonika 的眼睛傳感器。我正在制作的應用程式發現傳感器,掃描后我得到以下資料
制造商資料。
{89A: [01, B7, 0A, 01, 2C, 0D, FA, C7, 00, AC, 6B]}.
服務資料
{0000FEAA-0000-1000-8000-00805F9B34FB: [00, 02, 2E, 50, 80, 6A, A3, 82, 55, AA, D9, FA, 2A, 15, 4E, 2D, 00, 55, 00, 00]}
我想從這些資料中提取溫度、濕度等,但我不知道該怎么做。我在這里找到了類似的問題,但我不知道它如何適合我的情況。
傳感器的檔案可以在這里找到。Protocol Description部分關于資料的資訊很少,但我不知道如何使用它。
任何幫助將不勝感激。謝謝
uj5u.com熱心網友回復:
Protocol Description似乎很好地解釋了格式。
以問題中的十六進制數字為例Manufacturer data:
[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
使用代碼執行此操作應與您鏈接到的問題相同,但資料Endian.big格式為默認設定。例如:
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());
}
列印到控制臺:
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/439616.html
上一篇:為什么在flutter中使用initState時變數的值不會改變
下一篇:移動浮動動作按鈕顫振
