Error Error("json: unsupported value: NaN")

The error is not in the lines you posted, but is thrown when TTN tries to convert the return value of your Decoder function into a JSON text representation. So, we’d need to see all code to guess what’s wrong.

(Aside: also note that 0xF is really the same as 0x0F; probably not the if condition you really want.)