Thanks for the reply Paul. Now, about you observations:
PaulS:
It can't possibly get a void array. It CAN get an empty array, but that is NOT the same as an array of type void.
Right, wrong concept. My bad, still according to the code from the cooking hacks link, I should get a char array with valid characters, not an empty array.
PaulS:
Please do not post code full of commented out code. The commented out code is obviously NOT part of the problem. Delete it before posting code.
Got it. I edited my first post to remove all the commented code.
PaulS:
char sms[] = "";You've created an array that can hold 0 characters. How is THAT useful?
sprintf(aux_str, "AT+CMGS=\"XXXXXXXXXX\"", strlen(sms));sms is NOT a string (because there is not room to hold even the NULL terminator, so you should not be passing it to a function that expects a string.
Both are related. Those parts of the code and plenty of others are part from tutorials from this site: SIM808: GSM/GPRS + GPS – Prometec (Warning: It's in spanish). For those to specific parts, now that I think about it, aren't really useful...I could just send the AT command directly with enviarAT() and be done with the sms variable entirely.
PaulS:
The do/while statement in enviarAT(), in which you have an if statement that makes sure that the do/while statement does nothing, is NOT appropriate. Use a while statement.while(Serial.available()>0) Serial.read();Why is it necessary to ensure that the incoming serial buffer is empty?
The do/while statement in reportar(), in which you have an if statement that makes sure that the do/while statement does nothing, is NOT appropriate. Use a while statement.
Those 3 parts are parts of codes from the links provided in this and my previous message. I didn,t alter them as they worked fine, but if using a normal while statement could decrease memory usage, I can try it.
PaulS:
strtok(gpsdata, ",");
strcpy(latitud, strtok(NULL, ","));
strcpy(longitud , strtok(NULL, ","));
You must ALWAYS check that strtok() returned a valid pointer.
The response from AT+CGPSINF=0 is like this: "+CGPSINF: 0,4316.645000,257.667700,14.800000,20170117141311.000,0,9,1.796440,198.850006". The first code block after variable declarations in reportar() are supposed to save that string in the gpsdata array but a Serial.print of that array showed nothing in the Serial Monitor.
First, I made this modification before the tokenization:

Then, after running the code and sending the message, this happens:

The line that reads "Orden 3 PIN 0000AT+CGPSINF=0" is the sms sent followed inmediatly by the AT command that gets GPS data (despite looking wrong, you can see that up to that point, everything works ). Then after the ACK of the AT command's response (which is filled with zeroes as I'm in a place with bad reception and I don't have screenshots of the test with proper GPS data but that ended similarly) you can see an empty space between the freeMemory() prints. Finally, after the "CONNECT OK" line, the program crashed. This is the code I first posted on this topic.