Split Raw Message

Dear Masters..

I have Raw data like this "02 88 0001 1B83 000147 0000 FFFDB1F2 8D 03". Is there anyone who can help me?. How do I write code to separate the data like this.

02 - STX
88 - Message Type
0001 - Node Address
1B83 - Virtual Device
000147 - Object ID
0000 - Parameter ID
FFFDB1F2 - Value
8D - Checksum
03 - ETX

Thank You

Best Regards

Donny

Easy going in standard Groovy by using split(), e.g. (untested):

def sRawData = '02 88 0001 1B83 000147 0000 FFFDB1F2 8D 03'
def (sSTX, sMessageType, sNodeAddress, sVirtualDevice, sObjectID, sParameterID, sValue, sChecksum, sETX) = sRawData.split()
1 Like

@Jost thank you for your reply. What if there are no spaces, is it the same way? like "028800011B830001470000FFFDB1F28D03"

You could parse that string out using webcore. But I suspect that path is a bit steep to climb if you are new to webcore.

If you make it a Byte Array you could manually split it, i.e.

ByteArray ba = new ByteArray(028800011B830001470000FFFDB1F28D03)
def sStx = ba[0]
def sMessageType = ba[1]
def sNodeAddress = ba[2..3]
def sVirtualDevice = ba[4..5]
…
4 Likes

You might find the HexUtils package helpful:
https://docs.hubitat.com/index.php?title=HexUtils_Object

3 Likes

Thank you sir. After I read the documents from @tony.fleisher . Thank you @tony.fleisher . If the Raw Data is a String, and I want to convert it to bytes. How do I write the code? I've tried to make it but still error.

Should be something like:

String stringData = "028800011B830001470000FFFDB1F28D03"
byte[] byteStr = hubitat.helper.HexUtils.hexStringToByteArray(stringData)
2 Likes

In Groovy you even don't need to convert the String to a ByteArray, as a String is already an Array of Chars. :wink:

String sRawData = '028800011B830001470000FFFDB1F28D03'
String sSTX = sRawData[0..1]
String sMessageType = sRawData[2..3]
String sNodeAddress = sRawData[4..7]
// ...
2 Likes

No, as split() needs a separator String (space is the default).

1 Like

Thank you for your help @Jost @thebearmay @tony.fleisher @Pantheon

1 Like

Sorry Gentleman's. I need your help one more time. I've been able to get the data I want. How do I convert it to decimal.

Hi Donny:

The conversion that you want is non standard if this is for your Blu 100 driver. See my function 'decodeGainVal(val)' from our past private message session.

1 Like

oh.. understood @tomw

Can the case be used for 2 conditions? Example: switch(sObjectId, sParameterId)

I'm late to the party but maybe there is something useful in this post...