Separate out different messages

I want to know when I get a LoRA Join message rather than other data packets - so for instance the following is a join message - I want to separate out these from other messages - but trying to look for instance ---

if (msg.payload.join_accept.session_key_id){
                   // do nothing 
 } else if (msg.payload.uplink_message.decoded_payload.Cert > 0){

does not work as the msg.payload.join_accept.session_key_id does not exist in other messages - would love some thoughts - thanks, Garth

{"end_device_ids":{"device_id":"18-audio","application_ids":{"application_id":"costa-rica-development"},"dev_eui":"xxxxxxxxxx","join_eui":"xxxxxxx","dev_addr":"xxxxxxx"},"correlation_ids":["as:up:xxxxxxxx","gs:conn:xxxxxxx","gs:up:host:xxxxxxxk:xxxxxxx","ns:uplink:xxxxxxx","rpc:/ttn.lorawan.v3.GsNs/HandleUplink:xxxxxxx","rpc:/ttn.lorawan.v3.NsAs/HandleUplink:xxxxxxx"],"received_at":"2023-09-18T19:04:27.003981894Z","join_accept":{"session_key_id":"xxxxxxxxxx==","received_at":"2023-09-18T19:04:xxxxxxxx'

Admin edit: wrap code in backticks

You can use a switch mode to direct messages by adding 2 entries

  1. Has key : msg.payload.join_accept.session_key_id
  2. Otherwise

Then you don't need to worry about testing for the existence of the key at all

Thanks so much Steve

how do you recommend implementing this as an if statement throws an error if that part of the payload is not present - indeed a Switch statement would be a great approach

actually I got it - thanks Genius!!

OK I'm back

so this works msg.payload.join_accept and catches all Join requests which is great
However if I try

  1. Has key : uplink_message.decoded_payload.Cert

I do not get a match, even though this exists in the alternative uploaded message.
Any advice would be welcome - thanks

Show us the incoming message copied from the debug pane using Copy Value in the debug pane, and also screenshot of how you have setup the Switch node.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.