Measuring BBT in the morning

Do I need to measure my bbt right after my REM sleep or just when I wake up?

The reason I ask is because I tend to wake up around 4am. I go back to sleep but the sleep is no longer deep sleep. Does that affect the measurements?