Bonjour,
pierrot10:
J'au trouvé une petite fonction quo va affché la RAM. Je vous avoue pas trop la comprendre
En même temps je connais pas beaucoup de personne capable de me lister les variables internes de GCC gérant l'allocation de la mémoire ...
const String apn = "internet"; // access-point name for GPRS
const String ip = "xx.xxx.xx.xxx"; // IP address of server we're connecting to
const String host = "server.dyndns.org"; // required in HTTP 1.1 - what's the name of the host at this IP address?
const String requests = "GET /opt/updatesql.php?lat=1.10&long=1.20&alt=1.30&speed=1.40&course=1.50 HTTP/1.1";
const String request = "GET /opt/updatesql.php";
const String request_end = " HTTP/1.1";
const String useragent = "Mozilla/5.0";
Tout ça devrait être des const char[] en flash (voir PROGMEM)
int redLedPinGPRS = 13;
int greenLedPinGPRS = 12;
int redLedPinGPS = 11;
int greenLedPinGPS = 10;
"const byte" au lieu de int
Serial.println("");
pas besoin de quote :
Serial.println();
cell.println("AT+CMGF=1"); // set SMS mode to text
cell.print("AT+CMGS="); // now send message...
Toutes les chaines de caractères devraient être en flash pour économiser de la RAM (macro F("...."))
cell.print("\"");
Pour un caractère write() est bien plus adapté :
cell.write('"');
//strcpy(data, "date");
//strcat(data, ",");
/*
strcpy(coords, request);
*/
strcpy(coords, "?");
strcat(coords, "lat=");
// Latitude
dtostrf(flat, 2, 4, coordinate);
strcat(coords, coordinate);
strcat(coords, "&");
//Longitude
strcat(coords, "long=");
dtostrf(flon, 2, 4, coordinate);
strcat(coords, coordinate);
strcat(coords, "&");
//Altitude
strcat(coords, "alt=");
dtostrf(falt, 2, 4, coordinate);
strcat(coords, coordinate);
strcat(coords, "&");
//Speed
strcat(coords, "speed=");
dtostrf(fspeed, 2, 4, coordinate);
strcat(coords, coordinate);
strcat(coords, "&");
//dtostrf(fcourse, 2, 4, coordinate);
//Course
strcat(coords, "course=");
strcat(coords, TinyGPS::cardinal(gps.f_course()));
//strcat(data, "\r\n");
/*
// Terminate the string
strcat(coords, " HTTP/1.1");
// Terminate the string
strcat(coords, "\0");
*/
Serial.println(request + String(coords) + request_end);
Sérieusement ? ... c'est moche ...
De même que :
Serial.println(request + "?lat=" + char(flat) + "&long=" + char(flon) + "&alt=" + char(flat) + "&speed=" + char(fspeed) + "&course=" + TinyGPS::cardinal(gps.f_course()) + "&age=" + char(fage) + request_end);
... en plus d'être complétement faux (caster un float en char c'est comme vouloir faire passer un camion dans le coffre d'une fiat panda).
Tu peut envoyer une chaine de caractères sans retour ligne morceau par morceau c'est tellement plus simple ...
Serial.print(request);
Serial.print(F("?lat="));
Serial.print(flat, 4);
Serial.print(F("&long="));
Serial.print(flon, 4)
Serial.print(F("&alt="));
Serial.print(flat, 4);
Serial.print(F("&speed="));
Serial.print(fspeed, 4);
Serial.print(F("&course="));
Serial.print(TinyGPS::cardinal(gps.f_course());
Serial.print(F("&age="));
Serial.print(fage, 4);
Serial.println(request_end);
String ready = getMessage();
if(ready == "+SIND: 1"){
Serial.println(F("> SIM is inserted ..."));
}
if(ready == "+SIND: 10,\"SM\",1,\"FD\",1,\"LD\",1,\"MC\",1,\"RC\",1,\"ME\",1"){
Serial.println(F("> SIM is ready ..."));
}
if(ready == "+SIND: 11"){
GPRS_registered = 1;
Serial.println(F("> Module is registered to network ..."));
}
if(ready == "+SIND: 3"){
Serial.println(F("> GPRS is partially ready ..."));
}
if(ready == "+SIND: 4"){
GPRS_AT_ready = 1;
Serial.println(F("> GPRS is ready ..."));
}
if(ready == "+SIND: 7"){
Serial.println(F("> Emergency only ..."));
}
if(ready == "+SIND: 0"){
Serial.println(F("> SIM card removed"));
}
Fait en sorte que ta fonction getMessage() stocke le message reçu dans un char[] de taille fixe (en variable globale).
Ça t'évitera d'allouer des String à tout bout de champ en faisant des if qui cast implicitement les chaines de char en String.
En plus avec un tableau en variable globale les chaines de char constantes de tes if pourrons être mis en flash avec F("...) et testé avec la fonction strcmp_PF().
Remarque : c'est à coup sûr cette fonction qui fragment le peu de RAM qu'il te reste et fait tout planter.
Pour résumer :
- remplace toutes tes utilisations de String par des tableaux de char, tu devrais te rendre compte immédiatement à quel point le code actuel tue la RAM.
- encapsule toute tes chaines de caractères constantes par F("...") pour les stocker en flash
- évite les concaténation et les traitements inutiles.