Application Port Switch Bug

Hello,
I encountered what appears to be a bug when using application ports to handle downlinks.
I use the application port in a switch-case statement in my downlink handler. I am sending downlinks like so

I am using port 2 for my uplinks and downlinks.
My log says this
image

As you can see, it hits both port == 2 and port == 5 cases.
Here is my downlink handler

Any help is appreciated!

Using if-else if statements work.
So it just the switch-case statement that is at fault.
Port is a uint8_t variable, I assumed that the switch-case statement supported it.

It’s a problem inherent in C-style case statements. They fall through to the next case (it’s a feature) unless you end with a break;

Please put in some break statements at the end of each case block.

2 Likes

To make it complete a skeleton for a ‘proper’ switch … notice the breaks and the default:

switch (expression)
​{
    case constant1:
      // statements
      break;

    case constant2:
      // statements
      break;
    .
    .
    .
    default:
      // default statements
}
1 Like

Doh! I forgot. Thanks guys :sweat_smile: