ISR not in IRAM error with Wemos mini d1

Try

void IRAM_ATTR beam_break_ISR()
{
I = I+1;
flag = 1;
}

Arduino and Esp32 Interrupts (ISR) – MAlabdali