Je réalise un projet dans lequel je dois faire fonctionner un shield GPRS et un shield GPS avec un Arduino Uno.
J'ai un code qui fonctionne parfaitement.
Je souhaite ajouter une fonctionnalité, pour cela je commence par ajouter une fonction.
Et sans même appeler cette fonction mon sketch ne marche plus, il affiche n'importe quoi sur le serial.
J'ai essayé FreeMemory pour voir si j'avais un dépassement de mémoire.
Ce n'est pas le cas.
La fonction qui fait "planter" le sketch lorsque je la rajoute :
void SubmitHttpRequest(float lat, float lon)
{
char adresse[150];
long lat2, lon2;
lat2=lat*10000;
lon2=lon*10000;
mySerial.println("AT+CSQ");
delay(100);
mySerial.println("AT+CGATT?");
delay(100);
mySerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");//setting the SAPBR, the connection type is using gprs
delay(1000);
mySerial.println("AT+SAPBR=3,1,\"APN\",\"FREE\"");//setting the APN, the second need you fill in your local apn server
delay(4000);
mySerial.println("AT+SAPBR=1,1");//setting the SAPBR, for detail you can refer to the AT command mamual
delay(2000);
mySerial.println("AT+HTTPINIT"); //init the HTTP request
delay(2000);
sprintf(adresse,"AT+HTTPPARA=\"URL\",\"ADRESSE DU SITE");
mySerial.println(adresse);// setting the httppara, the second parameter is the website you want to access*/
delay(1000);
mySerial.println("AT+HTTPACTION=0");//submit the request
delay(10000);//the delay is very important, the delay time is base on the return from the website, if the return datas are very large, the time required longer.
mySerial.println("AT+HTTPREAD");// read the data from the website you access
delay(300);
mySerial.println("");
delay(100);
}
Et vlan un tableau de char de 150 octets, ... je chercherai pas plus loin !
Un jolie cas typique de mémoire RAM insuffisante ...
Toute les chaines de caractères des .println("blabla") -> .println(F("blabla"))
F("...") mais la chaine de char en flash et non en RAM.
Ensuite, ça c'est du non-sens total :
sprintf(adresse,"AT+HTTPPARA=\"URL\",\"ADRESSE DU SITE");
mySerial.println(adresse);
Pourquoi bouffer 150 octets pour 35 malheureux char fixe !
(Il te manque un " en fin d'adresse au passage)
void SubmitHttpRequest(float lat, float lon)
{
/*long lat2, lon2;
lat2=lat*10000;
lon2=lon*10000;*/ // Variables jamais utilisées
mySerial.println(F("AT+CSQ")); // Sert à rien de demander la qualité du signal GSM si tu en fait rien derrière
delay(100);
mySerial.println(F("AT+CGATT?"));
delay(100);
mySerial.println(F("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\""));
delay(1000);
mySerial.println(F("AT+SAPBR=3,1,\"APN\",\"FREE\""));
delay(4000);
mySerial.println(F("AT+SAPBR=1,1"));
delay(2000);
mySerial.println(F("AT+HTTPINIT"));
delay(2000);
mySerial.println(F("AT+HTTPPARA=\"URL\",\"ADRESSE DU SITE\""));
delay(1000);
mySerial.println(F("AT+HTTPACTION=0"));
delay(10000);
mySerial.println(F("AT+HTTPREAD"));
delay(300);
mySerial.println();
delay(100);
}