Payload with mixed data type

The lines below include the definition of the payload used in an Arduino-based node.

// Data Packet to Send to TTN
// loraData[0:6] = Sensor ID[0:6]
// loraData[7] = HiByte (battery)
// loraData[8] = LoByte (battery)
// loraData[9] = HiByte (temperature)
// loraData[10] = LoByte (temperature)
unsigned char loraData[11];

Bytes [0:6] represent a text string of the form “PMNTC01”, while Bytes [7:10] represent data of the type uint16_t.
In the Payload Decoder, I am able to decode either the text string or the data separately, but not both at the same time.

Can you indicate how to define the Payload Decoder to decode the text string and the data at the same time?

Thanks,
Oscar.

Don’t do that!

This is wasteful and only duplicates the sensor’s device address or EUI.

Use the already present unique information instead, if you need to do a lookup do that in whatever receives the information.

1 Like

In addition to what cslorabox said, use (f)port to indicate different types of payload, if it fits your use case. Depending on your use case, it might be better to send multiple values in one larger message than sending multiple messages with different port.

In addition to the good advice already posted (sending a device ID is redundant!),
i can hardly think of any use case where sending a string as a string makes sense.
you will always be more efficient by sending a number and mapping that number to a text, after the costly transmission. You could pack 256 sentences into one byte.

1 Like

I think what everyone is saying is that you don’t need to know how to decode the text string & the data at the same time as you shouldn’t be sending a text string.

And as you appear to know how to decode the data, your problem is solved.

As for the sensor id, you can look it up from the meta data that comes with the payload.

The feedback received makes sense and I will make the changes.
Could I get additional information on Tutorials on how to use the Decoder, Converter, Validator and Encoder options of the Payload Format section?

There are plenty decoder examples in messages on this forum, you will need to search a little but plenty can be found.
Don’t use converter and validator as those will disappear with V3 of the stack.

1 Like