How to insert a variable in a "he wattr" payload?

In the below command I would like to replace the 076162636461610d with the variable serialdata.
I've tried ${serialdata} and $[serialdata] neither work.
I also tried, without success:

    def serialdata = {104 3 02 0E00 42 076162636461610d }
    "he raw ${device.deviceNetworkId} 0x01 0x01 0x0014 ${serialdata}"

any suggestions?
thanks
John

Working code:

def WriteAttr_() {
    def serialdata = 076162636461610d
    "he raw ${device.deviceNetworkId} 0x01 0x01 0x0014 {104 3 02 0E00 42 076162636461610d }"    // Works !!
}
1 Like

Seems like you want this to be a String, in which case the value would need to be enclosed in quotes:

def serialdata = "{104 3 02 0E00 42 076162636461610d }"

As is, you've instead create a closure (with the curly braces) that ... does IDK what but definitely not what you intend. :smiley:

Same thing here:

Otherwise, you've done the same (in this case, probably defined in a variable serialdata interpreted as Double due to the d at the end and with octal representation given the 0 at the beginning -- and happening to have only valid octal digits in between -- tricks you can use to force different interpretation of literal values in Groovy).

Otherwise, your string interpolation looks correct!

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.