There are a couple of things here that are fundamentally the wrong way to handle AT commands.
First of all, never, never, never, ever use delays like the function delaygsm. You must change the logic for processing so that you after sending a command, you do absolutely nothing but reading responses from the modem until you get a final result code before starting on the next command. See this answer for details on that.
Turning off echo with ATE0 only gives you slightly less text to parse, but there is no way around. You MUST read and parse the responses given back by the modem. It is not that complicated, just follow the directions given in the answer linked above.
Also notice that AT command lines should be terminated with '\r'
(or written as 0x0d
) only and nothing else, see this answer for details.