I suggest, forget loops in Open At baceuse the Watchdog Timer will reset the module after a time.
I experienced, that some commands don’t like calling after itself.
Use timers everywhere, the program will benefit it.
I agree with tomalex, do not use ‘while’ or big loop with ‘for’ because of the watchdog timer.
The watchdog timer is set to 4.5 seconds (Open AT Development Guide, chapter about security), so if your Open AT application keeps the hand more than 4.5 seconds in a loop then the module resets.
The best way is to use timers to allow the core software to work properly.