how can I get the proper value when using BLE GATT and Hex Values #457
-
Hello everyone, this is my first time here. I have a client who needs me to connect to a BLE device and get readings from it using Javascript. I am successfully connecting to the device. But now it is time to get readings. Here is the information they sent me: "To provide efficient transmission of data at higher speeds a CondensedDecimalArray type can be used. This will be transmitted as an array of 32-bit signed integer values in little endian format each being a hex string of 4 bytes. The first two bytes of the array are a 16-bit unsigned integer value in little endian format. This is the number of readings in the array. Each reading should be read from the array and processed by the client application." So here is my code block: BleClient.startNotifications(device.device.deviceId, this.CURRENT_READING_SERVICE, this.CONDENSED_VALUE_CHR, (value) => {}); I am just struggling on how to accurately get a value from this. I see it is a 32 - bit signed integer value in little endian format. So looking at the docs of the plugin, i can use getInt32(0, true) So my thoughts are this: use getInt16(0, true) and getInt16(1, true)? That would be the first two bytes of the value array to determine how many readings are in the array? Am i on the right track? Any help is greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments
-
Do you know what is a DataView and Buffer in Javascript? if not please read about them and make sure you understand them well, I suggest you to start from here. |
Beta Was this translation helpful? Give feedback.
-
I'm new to DataView and interacting with Bits in JavaScript. That's why I thought I could reach out for some guidance. |
Beta Was this translation helpful? Give feedback.
-
Ok you should read more and test DataView yourself it will give you another superpower in JS :) |
Beta Was this translation helpful? Give feedback.
-
Okay cool! So I can just loop through the object like that. If the response is a array of 32 bit signed integers. It would be result.byteLength/32? Or are all responses always byteLength/8? |
Beta Was this translation helpful? Give feedback.
-
ok, please work more with JS DataView, it has some learning curve but it's important to understand how buffers are represented in a DataView
|
Beta Was this translation helpful? Give feedback.
-
also please for future discussions open a discussion thread instead of an issue, thanks in advance :) |
Beta Was this translation helpful? Give feedback.
-
Sorry, I am more of a lurker. Never really post much. Thank you. Your example is so much more helpful! I totally understand now and can apply this to my issue. I learn better by example than reading so after reading the DataView Docs and your example, it really makes a lot of sense! Thank you again! Hopefully this post can help others get an understanding too. |
Beta Was this translation helpful? Give feedback.
ok, please work more with JS DataView, it has some learning curve but it's important to understand how buffers are represented in a DataView