Greetings. Is there an easy way to insert a variable as part of a new payload path object? For example :
1 var dev = payload.data.message.dev_id
2 // Extract Device ID last 4 digits to use for identifying variables
3 var eui = dev.substr(12,4)
4 // Declare variables, including the decoding ‘payload_raw’ to HEX:
5 var raw = payload.data.message.payload_raw
6 var buf = new Buffer(raw, ‘base64’)
7 var hex = buf.toString(‘hex’)
8 // Now, extract how many bytes in the payload and add to a ‘payload_cnt’ variable:
9 var cnt = hex.length
10 // Add these new objects to the new payload variables :
11 payload.data.message.device_id = eui
12 payload.data.message.payload_hex = hex
13 payload.data.message.payload_cnt = cnt
The above works so far, but I would like in line 12 and 13 for ‘device_id’ / eui to be included. For example, if eui = ‘be76’ then path for line 12 would read payload.data.message.payload_hex_be76 or similar. Line 13 output would read payload.data.message.payload_cnt_be76 or similar.
Thanks, j