[英]How to get the correct temperature value from byte array
I'm trying to create a BLE app where i want to catch the value of the temperature from a device.我正在尝试创建一个 BLE 应用程序,我想在其中捕获设备的温度值。 I'm using Temp Sitter device.
我正在使用 Temp Sitter 设备。
I have this UUID=0000ffe1-0000-1000-8000-00805f9b34fb.我有这个 UUID=0000ffe1-0000-1000-8000-00805f9b34fb。 From here I get an array of bytes.
从这里我得到一个字节数组。
// For all other profiles, writes the data formatted in HEX.
final byte[] data = characteristic.getValue();
if (data != null && data.length > 0) {
final StringBuilder stringBuilder = new
StringBuilder(data.length);
for(byte byteChar : data)
stringBuilder.append(String.format("%02X ", byteChar));
intent.putExtra(EXTRA_DATA, new String(data) + "\n" +
stringBuilder.toString());
}
Here are some hex results:以下是一些十六进制结果:
AA 06 11 00 3E 0D 00 62 ---
AA 06 11 00 43 0D 00 67 ---
AA 06 11 00 49 0D 00 6D
Can any one help me how to read the exact value of this array?任何人都可以帮助我如何读取此数组的确切值吗?
After reverse-engineering the IRULU / Guangdong Biolight Meditech Temp Sitter app, it looks as if the message has this format:在对 IRULU / 广东百光医疗Temp Sitter应用程序进行逆向工程后,该消息看起来好像具有以下格式:
0 1 2 3 4 5 6 7
+------+------+------+------+------+------+------+------+
|Marker|Length|Type |Subtyp|Low |High |Unused|Chksum|
+------+------+------+------+------+------+------+------+
Example AA 06 11 00 3E 0D 00 62
The fields are:这些字段是:
The temperature value is stored in 0.01 degree (probably degree Celsius).温度值以 0.01 度(可能是摄氏度)存储。 So to extract it, you compute:
所以要提取它,你计算:
double temperature = ((message[5] & 0xff) * 256 + (message[4] & 0xff)) * 0.01;
In the above example, the result would be 33.90 °C.在上面的示例中,结果将为 33.90 °C。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.