Bonjour,
Je cherche une solution pour envoyer des données avec le format JSON.
En gros, j'ai un GPS qui me collect les positions toutes les minutes.
Aussi, j'ai un module GSM qui va les envoyer.
Simplement, si je me trouve en montagne, il n'y aura pas forcement une antenne GSM mais par contre le GPS fonctionnera.
J'ai aussi une fonction qui va envoyer les données collectée via le 3G.
Quand une coordonée GPS sont collectées, il faut qu'il garde ca sous fomat JSON
{
"2003-08-16 08:00:00": {
"co": "course",
"la": "lattitude",
"lo": "longitude",
"al":"altitude",
"ve":"speed"
}
}
Mais s'il n'y a pas plus de 3G, il faut qu'il conserve les positions suivante de maniere à avoir ceci, par exempl et si ce n'est pas fau
{
"2003-08-16 08:00:00": {
"co": "course",
"la": "lattitude",
"lo": "longitude",
"al":"altitude",
"ve":"speed"
}
"2003-08-16 08:01:00": { // there is no GSM connection, then it increment to record the data, and it will send in block when GSM will be available
"co": "course",
"la": "lattitude",
"lo": "longitude",
"al":"altitude",
"ve":"speed"
}
"2003-08-16 08:02:00": {
"co": "course",
"la": "lattitude",
"lo": "longitude",
"al":"altitude",
"ve":"speed"
}
"2003-08-16 08:03:00": {
"co": "course",
"la": "lattitude",
"lo": "longitude",
"al":"altitude",
"ve":"speed"
}
}
Et une fois le 3G revenu, il envoi tout au serveur.
J'ai trouvé une librairie intéressante
mais je peine a la faire fonctionnée et j'aurais voulu savoir si vous auriez pas une autre solution avec exemple qui repondrait à mon besoin.
En attendant, voila mon code simplifié qui fonctionne avec la librairie que je vous ai donné juste dessus.
Connaitriez vous cette librairie? pourriez-vous m'aider?
A savoir que la fonction SendDATA est appelée chaque miniute. Chauqe minute cette fonction va connaitre la position, grace a la fonction gps.getPar(lon,lat,alt,time,vel); Puis s'il y a pas de 3G conserve la position si non envoi
// Send data to the sremote erver
void SendData(void){
#ifdef DEBUG
Serial.println(F("\nSENDING COORDS TO THE REMOTE SERVER"));
#endif
// It collect statictis and return 0,1,2 or or 3. See below
stat=gps.getStat();
#ifdef DEBUG
if(stat==0){
Serial.println(F("GPS OFF"));
Serial.println(F("No coords sent"));
}else if(stat==1){
Serial.println(F("NOT FIXED"));
Serial.println(F("No coords sent"));
}else if(stat==2){
Serial.println(F("2D FIXED"));
}else if(stat==3){
Serial.println(F("3D FIXED"));
}
#endif
//Get data from GPS
// Send the data only if the are FIXes, otherwise giveup the send function
// This is to avoid battery consomation
if(stat == 2 || stat == 3 || stat == 0){
// I added stat==0 for testing, as I do not have always fixes. It does not matter if I have 0.00000, for JSON testing
// That function collect the coordinate. It's works fine
gps.getPar(lon,lat,alt,time,vel); // the 5 variable a declare above. Ex: char lon[15];
// Convert Int to char
char course_id[6] = {0};
sprintf(course_id, "%d", courseid);
puts(course_id);
/* EXPLICATION:
HERE IS MY JSON and it does not display my JSON string (value)
Be aware and I do not know I did it correctly
I do declared the following below my librairies, on the top of my script:
//JSON
aJsonObject *root,*online;
char* value;
In my steup(), I add this code:
//JSON
root=aJson.createObject();
*/
// HERE IS MY JSON CODE
aJson.addItemToObject(root, time, online = aJson.createObject());
// the variable time come from the function gps.getPar(lon,lat,alt,time,vel);
aJson.addStringToObject(online,"co", "course"); // I will later change "course" with the varibale course_id
aJson.addStringToObject(online,"lo", "long"); // I will later change "long" with the varibale lon
aJson.addStringToObject(online,"la", "lat"); // I will later change "lat" with the varibale lat
aJson.addStringToObject(online,"al", "alt"); //etc
aJson.addStringToObject(online,"ve", "vel"); //etc
*/
value = aJson.print(root);
Serial.print("value : ");
Serial.println(value); // that value display nothing, empty , why
#ifdef DEBUG
Serial.println(F("Sending now... . Wait for 5 to 10 seconds"));
#endif
if(inet.httpPOST(host, port_post, path_post, value, "Result", 0)){
// Emvoi reussi. JESON peut etre effacé
}else{
// Envoi pas possible, JSON doit ajouté les positions suivantes. Comment on fait?
}
#ifdef DEBUG
Serial.print(F("Data sent : "));
Serial.println(value);
Serial.println(F("Wait for 10 second"));
#endif
delay(10000);
}
enterCommand();
}
// End sendDATA()
Merci pour vos lumières et j'espère avoir donné assez d'info. Dites moi si ce n'est pas le cas.