Detect watchdog timer reset

Hello,
I have a problem with the watchdog timer.
I can activate it, it works, because it resets the microprocessor, but when the arduin restarts I can not understand if it started normally or was a watchdog timer reset.

I read the MCUSR but it’s always 0!

#include <avr/wdt.h>
unsigned long i;
uint8_t mcusr_temp;

void setup() {
  // put your setup code here, to run once:
  //wdt_disable();
  mcusr_temp = MCUSR;
  MCUSR = 0;
  Serial.begin(9600);
  ResetTest();
  i=0;
  wdt_enable(WDTO_2S);
}  


void loop() {
  // put your main code here, to run repeatedly:
  i++;
  delay(500);
  Serial.println(i);
  //wdt_reset();
}

void ResetTest(){
Serial.println(mcusr_temp);
if(mcusr_temp & (1<<WDRF)){
   // a watchdog reset occurred
   Serial.println("WDT");
}
if(mcusr_temp & (1<<BORF)){
  //  a brownout reset occurred
  Serial.println("BOR");
}
if(mcusr_temp & (1<<EXTRF)){
  //  an external reset occurred
  Serial.println("EXT");
}
if(mcusr_temp & (1<<PORF)){
  //  a power on reset occurred
  Serial.println("POR");
}
}

What am I doing wrong?

I assume you are using an Arduino board with Optiboot installed.

The watchdog is also used to end an upload. As long as you are using Optiboot you will not be able to tell the difference between watchdog-expired and first-run-after-upload.

This is an example of how to detect a watchdog reset...
https://github.com/Optiboot/optiboot/blob/master/optiboot/examples/test_reset/test_reset.ino

This has some of the gory details...

Thank you for the reply.

But the example does not seem to work so well, in response i get

Reset flag test
Have reset flag value 0xFE Watchdog Brownout External Unknown

It takes all the values.
I use an Arduino UNO

I should have included...

I assume you are using an Arduino board with a recent version of Optiboot installed.

You may have to update your bootloader.