Byte array problem . can't access elements of the array

I'm trying to work with a string that is a concatenation of positive bytes.
The string is: Zigbee Msg# 334A780F22EE0100
Where I would like to be able to test and get value for each byte:
33 4A 78 0F 22 EE 01 00

However I can't seem to address an individual element in the byte array.

Below is my code. You can see the last three "" shows my latest attempts. I'm starting to think there may be something special of this type of array.

Does anyone see where I'm going wrong?

def parse(String description){  "Raw Description#$description"

//    Map map = [:]
    def event = zigbee.getEvent(description)

    //if (event) sendEvent(event)

    if (description?.startsWith('read attr -')){

        def descMap = zigbee.parseDescriptionAsMap(description)

        if (descMap.cluster == "0014" && descMap.attrId == "000E"){     // zigbee spec 0x000C= read analog cluster  0x0055 = present value
            ZigbeeHexMap = descMap.value
   "Zigbee Msg# $ZigbeeHexMap"
            byte[] xarray = hubitat.helper.HexUtils.hexStringToByteArray(ZigbeeHexMap)
   "fullarray=  $xarray"
   "byteA=  $xarray(3)"
   "byteB=  $xarray[3]"
   "byteB=  $xarray:3"
} // --- parse ---

xarray[3] = 0x78 = 120

Then I a would have thought the line: "byteB= $xarray[3]"

would have logged 0x78

instead of
byteB= [51, 74, 120, 15, 34, -18, 1, 0][3]

I see now for some reason the does not like the array element but will print the correct value if I assign the element to a "byte myvalue" first.

Thank you.

Try: "byteB= ${xarray[3]}"

(Might still show it as 120 though).


This works too. Shows the hex value 15

Again thanks.


Duh, I missed the zero based array, you'd think after all these years...


1 Like

I knew the array was zero based but until I could get individual elements I wasn't even thinking of which element I referenced.

1 Like