Hi,
I’m very new to TTN and am doing some fiddling with Node-Red to convert a hex payload from a TTN water level sensor. Whilst the Javascript code in the TTN console (decoder) works fine, I need to make it work in plain old Node-Red.
When I pass in a HEX string into the decode, it doesn’t work - and I’ve figured out that its because (I think) I’m sending a string (not 8 bits of hex) into the function.
I’m assuming I’m not representing the hex string properly - and the switch is getting strings not integers returned (so its just defaulting out and doing nothing)
Aside, note that a LoRaWAN application payload is really an array/buffer/list of bytes, so: values from 0 to 255. Hexadecimal is just one (of the many) human-readable representations of that.
Aside: your decoder does not support negative temperatures. See the post I quoted from above for a fix.
However, you shouldn’t be processing a human readable hexadecimal text string. TTN’s MQTT Data API and HTTP Integration will give you msg.payload.payload_raw in Node-RED (if you converted the JSON text into a JavaScript object) with the Base64-encoded raw data, not some human readable hexadecimal text.
If you’re somehow getting a hexadecimal text payload from TTN, then your sensor is basically sending text, and even worse: text that only uses 16 out of the possible 256 characters. (But I assume you’re converting the binary payload into a hexadecimal text yourself, somewhere?)
For now I’m just testing code that translates the ellenex sensor payload to JSON locally in prep for some other projects. I’m not actually ingesting this data from TTN with this method (I’m just using the NNT Node-red node), just using the code examples to familiarise myself with the sensor.