Inserting hexadecimal value into a buffer

Below is my function. It works for the most part, except I'm having an issue inserting the temperature in HEX to index 11 of the buffer. The issue is the value of index 11 does not change to the value I'm expecting. I checked the math in the code and it is calculating the correct decimal value. The issue appears to be with inserting the hexadecimal value into the buffer.

const setpointDegE = float2int(2 * ((5/9) * (msg.payload-32))) //convert payload DegF to DegE
const setpointHexDegE = toHex(setpointDegE) //convert decimal to hexadecimal 
// input would be msg.payload
const buffer = Buffer.from([0xca,0x09,0x06,0x00,0x4f,0x01,0x00,0x00,0x67,0x00,0x07,0x2a]);
buffer[11] = setpointHexDegE;
const length = parseInt(buffer[1]) + 2 // Get the length of the packet 
// Calculate the checksum by summing up values
let checksum = 0;
for (let i = 1; i <= length; i++) {
    checksum += buffer[i];
}
const checksumHex = checksum & 0xff //limit the HEX number to 8-bits
const buf2 = Buffer.from([checksumHex])
const buf3 = Buffer.from([0x35])
msg.payload = Buffer.concat([buffer,buf2,buf3]);
return msg;

function toHex(d) {
    return ("0"+(Number(d).toString(16))).slice(-2).toUpperCase()
}
function float2int (value) {
    return value | 0;
}

Hexadecimal numbers contain letters therefore they are stored in string variables.

A buffer is essentially an array of bytes (AKA 8-Bit numbers)

The Buffer.from method expects an array of bytes. You are adding an array of string.

In other words, don't covert anything to hexadecimal strings before adding to the buffer. Add the number value to the buffer.

(Look closely at what you're doing with setpointHexDegE)

Ps, your code is unnecessarily complex. Build your data in an array using the push method to append the calculated numbers (and only push number vars, not hexadecimal strings). When it's done, convert the full thing to a buffer.

For debugging, use node.warn({data}) in your code (where data is the thing you want to check) to ensure you've only added decimal numbers to the array.

Something like:

const setpointDegE = Math.floor(2 * ((5 / 9) * (msg.payload - 32))) //convert payload DegF to DegE

// input would be msg.payload
const data = [0xca, 0x09, 0x06, 0x00, 0x4f, 0x01, 0x00, 0x00, 0x67, 0x00, 0x07]
data.push(setpointDegE)

const length = data[1] + 2 // Get the length of the packet 
// Calculate the checksum by summing up values
let checksum = 0;
for (let i = 1; i <= length; i++) {
    checksum += data[i];
}
data.push(checksum & 0xff)
data.push(0x35)

// convert data to buffer & return it
msg.payload = Buffer.from(data)
return msg;