Replies: 3 comments
-
|
for example, this javascript does something similar, but I do not know how to integrate this in Serial-Studio to be functional: function extractIntegersFromHexString(hexString, positions) { // Example usage: |
Beta Was this translation helpful? Give feedback.
-
|
Hi! I recommend checking out the HexadecimalADC example for an example of using Serial Studio to parse binary data. To begin, create your project as you normally would by adding groups and datasets with relevant titles, frame indices, and settings. Next, modify the frame parser function to ensure it returns a JavaScript array containing your decoded values, incorporating logic to convert hex data to numbers. Make sure to enable the “Hexadecimal” data conversion method in the project editor so that the JS parser function receives a hexadecimal string representing the binary data of the frame. To help with debugging, you can use For example, if your project includes a group with two datasets (e.g., temperature and humidity), the parse function should handle the hexadecimal byte stream and append the decoded values to the frame array. This ensures your data is correctly parsed and displayed within Serial Studio's interface. |
Beta Was this translation helpful? Give feedback.
-
|
By the way, here is an example (untested) implementation that might get you on the right track: /**
* This function parses a binary data frame (represented as a hexadecimal string),
* and extracts specific byte locations for temperature and humidity, converting
* them into decimal values.
*
* @param[in] frame The latest received frame as a hexadecimal string.
* @return Array containing temperature and humidity as separate values.
*/
function parse(frame) {
let temperature, humidity;
// Ensure the frame has the minimum length to parse temperature and humidity
if (frame.length >= 18) {
// Extract temperature (Bytes 13 and 14)
let tempHex = frame.substring(24, 28); // Bytes 13 and 14 (zero-indexed positions 24 and 28)
temperature = parseInt(tempHex, 16);
// Extract humidity (Bytes 17 and 18)
let humidityHex = frame.substring(32, 36); // Bytes 17 and 18 (zero-indexed positions 32 and 36)
humidity = parseInt(humidityHex, 16);
} else {
console.log("Frame is too short to parse temperature and humidity.");
return [];
}
// Return the parsed temperature and humidity as an array
return [temperature, humidity];
}Please let me know if this solves your issue! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hex string result is returned from BLE device (thermometer+hygrometer as repetitive notification.
This contains encoded numbers for each measurement in one line of Hex, at known locations.
e.g.
AA AA A2 00 06 00 EE 02 44 01 00 31 55
where temperature is encoded in Byte 13 and 14, and humidity is encoded in byte 17&18.
How can I separate those values and display them as separate graphs ?
Beta Was this translation helpful? Give feedback.
All reactions