programming Problems with switch case

Hello together.

I experienced some strange behaviour of witch case in my arduino Sketch. For Context I have a Project where an ESP8266-01 receives Commands using TCP and sends them to my Arduino Mega using the Serial Ports. I use the SerialTransfer Library for that.

Now the switch case Statement in its entirety looks like this:

void readEspSerial() {
  boolean blink = true;
  
  if(myTransfer.available()) {
    blinkWhite();

    if(DEBUG_ESP_SERIAL) Serial.println("Serial available... Readin!");

    int processByte = (int) myTransfer.rxBuff[DP_PROCESS_BYTE];

    if(DEBUG_ESP_SERIAL) Serial.println("ProcessByte: " + String(processByte));
    
    switch(processByte) {

      case DP_PROCESS_MODE:
        if(DEBUG_ESP_SERIAL) Serial.println("Mode");
        mode = myTransfer.rxBuff[DP_MODE_BYTE];
        break;
      case DP_PROCESS_BRIGHTNESS:
        if(DEBUG_ESP_SERIAL) Serial.println("Brightness");
        brightness = (int) myTransfer.rxBuff[DP_BRIGHTNESS_BYTE];
        break;
      case DP_PROCESS_IR:
        if(DEBUG_ESP_SERIAL) Serial.println("IR");
        blink = false;
        unsigned long irCode = getIrValue(myTransfer.rxBuff[DP_IR_BYTE]);
        decodeResults(irCode);
        break;
      // THESE CASES DO NOT SEEM TO WORK.
      case DP_PROCESS_SATURATION:
        if(DEBUG_ESP_SERIAL) Serial.println("Saturation");
        // TODO
        break;
      case DP_PROCESS_HUE:
        if(DEBUG_ESP_SERIAL) Serial.println("HUE");
        for(int i = DP_HUE_START_BYTE; i < DP_HUE_END_BYTE; i++) {
          hueValues[i - DP_HUE_START_BYTE] = myTransfer.rxBuff[i];
        }

        mode = MODE_HUE;

        break;
      case DP_PROCESS_ON_OFF:
        if(DEBUG_ESP_SERIAL) Serial.println("ON_OFF");
        // TODO
        break;
      case DP_PROCESS_TIMER:
        if(DEBUG_ESP_SERIAL) Serial.println("Single Timer");
        int hours = (int) myTransfer.rxBuff[DP_TIMER_HOURS];
        int minutes = (int) myTransfer.rxBuff[DP_TIMER_MINUTES];
        int seconds = (int) myTransfer.rxBuff[DP_TIMER_SECONDS];

        unsigned long value = getTime(hours, minutes, seconds);

        myRTC.read(time);
        simpleTimer.startSingle(time, value);

        mode = MODE_TIMER;
        break;
      case DP_PROCESS_TIMER_DOUBLE:
        if(DEBUG_ESP_SERIAL) Serial.println("Double Timer");
        int hoursOne = (int) myTransfer.rxBuff[DP_TIMER_DOUBLE_HOURS_ONE];
        int minutesOne = (int) myTransfer.rxBuff[DP_TIMER_DOUBLE_MINUTES_ONE];
        int secondsOne = (int) myTransfer.rxBuff[DP_TIMER_DOUBLE_SECONDS_ONE];

        unsigned long value1 = getTime(hoursOne, minutesOne, secondsOne);

        int hoursTwo = (int) myTransfer.rxBuff[DP_TIMER_DOUBLE_HOURS_TWO];
        int minutesTwo = (int) myTransfer.rxBuff[DP_TIMER_DOUBLE_MINUTES_TWO];
        int secondsTwo = (int) myTransfer.rxBuff[DP_TIMER_DOUBLE_SECONDS_TWO];

        unsigned long value2 = getTime(hoursTwo, minutesTwo, secondsTwo);

        int repeat = (int) myTransfer.rxBuff[DP_TIMER_DOUBLE_REPEAT];

        myRTC.read(time);
        simpleTimer.startDouble(time, value1, value2, repeat);

        mode = MODE_TIMER;
        break;

      default:
        if(DEBUG_ESP_SERIAL) Serial.println("Default");
        
        blinkRed();
    }

    if(blink) {
      FastLED.show();
      delay(BLINK_DELAY);
    }

    writeMode();
    writeBrightness();
  }
}

For Context I copied the whole Method.

Now if the ESP sends a 7 as the first Byte, which determines the cases, the case of this (DP_PROCESS_TIMER_DOUBLE) does not get executed, neither does the default or any of the other cases. If i Comment all case Statements until the case(DP_PROCESS_TIMER_DOUBLE) out, the case does get executed and i cannot figure out why that is.

I tried commenting out single Cases, but i cannot find a pattern or a single Case which is responsible for this. Comparing the Byte and the predefine Values (e.g. DP_PROCESS_TIMER_DOUBLE) works perfectly fine.

Help would be appreciated. I can post the whole Code of my esp and Arduino including my Libraries if needed, but i think they are not important in this case.

Thanks in advance for Help!

You are declaring local variables in cases. You should have gotten some warnings that some of your cases were jumping over the initialization of local variables. NO CASES AFTER THIS ONE WILL BE COMPILED. If you didn't get warnings, set the compiler warning level to "All" in Preferences.

      case DP_PROCESS_TIMER:
        if (DEBUG_ESP_SERIAL) Serial.println("Single Timer");
        int hours = (int) myTransfer.rxBuff[DP_TIMER_HOURS];
        int minutes = (int) myTransfer.rxBuff[DP_TIMER_MINUTES];
        int seconds = (int) myTransfer.rxBuff[DP_TIMER_SECONDS];


        unsigned long value = getTime(hours, minutes, seconds);


        myRTC.read(time);
        simpleTimer.startSingle(time, value);


        mode = MODE_TIMER;
        break;

To fix it, put braces around the contents of all cases that have local variables:

      case DP_PROCESS_TIMER:
        {
        if (DEBUG_ESP_SERIAL) Serial.println("Single Timer");
        int hours = (int) myTransfer.rxBuff[DP_TIMER_HOURS];
        int minutes = (int) myTransfer.rxBuff[DP_TIMER_MINUTES];
        int seconds = (int) myTransfer.rxBuff[DP_TIMER_SECONDS];

        unsigned long value = getTime(hours, minutes, seconds);

        myRTC.read(time);
        simpleTimer.startSingle(time, value);

        mode = MODE_TIMER;
        }
        break;

Thank you soooo much, now everything is working fine!

I was working so long on this Project and now it works.