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
Jost
April 18, 2022, 8:11am
2
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
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
Jost
April 18, 2022, 8:44pm
9
In Groovy you even don't need to convert the String to a ByteArray, as a String is already an Array of Chars.
String sRawData = '028800011B830001470000FFFDB1F28D03'
String sSTX = sRawData[0..1]
String sMessageType = sRawData[2..3]
String sNodeAddress = sRawData[4..7]
// ...
2 Likes
Jost
April 18, 2022, 8:45pm
10
No, as split() needs a separator String (space is the default).
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.
tomw
April 18, 2022, 11:49pm
13
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
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...
In Release 2.1.5.123 there is a new advanced feature in Rule Machine that allows you to extract a token from a string, including from a String Variable.
[02%20AM]
Notice that the string used above is 123-456-7890. The Delimiter is the character (or characters) that will be used to break the string into tokens; "-" above. The index selects which token we want, starting with 0 for the left-most token. So, in this case, the result stored in Charlie would be 123.
That's not very useful as sho…