Bonjour,
J’aimerais bien reprendre ce post, car j’ai un problème similaire et récurant.
Je dois envoyer l’heure POSIX comme ceci
{“position”:{“value”:0,“timestamp”:1482529806000,“context”:{“lat”:46.21984,“lng”:6.14123,“IMEI”:“865067020750000”,“Battery”:99,“Quality”:“GSM”,“Tower”:“228,03,1771,2d6f,45,31”}},“battery”:99}
Le problème, c’est que j’arrive pas à convertit mon heure en posix, sans décimal
je dois convertir ceci
16/12/23,21:50:06+04
et j’arrive au mieux avoir
1482529806
alors que je dois avoir
1482529806000
Je procède ce cette manière
// buff has the value of : 16/12/23,21:50:05+04
printPosix(buff);
void printPosix(char * buff)
{
char format[23]="%d/%d/%d,%d:%d:%d+%d";
int year,month,day,hour,minute,second,timezone;
sscanf(buff,format,&year,&month,&day,&hour,&minute,&second,&timezone);
if (year<100) year+=2000;
// Here the prints are correct
Serial.println(year);
Serial.println(month);
Serial.println(day);
Serial.println(hour);
Serial.println(minute);
Serial.println(second);
Serial.println(timezone);
long epoch=0;
for (int yr=1970;yr<year;yr++)
if (isLeapYear(yr)) epoch+=366*86400L;
else epoch+=365*86400L;
for(int m=1;m<month;m++) epoch+=daysInMonth(year,m)*86400L;
epoch +=(day-1)*86400L;
epoch +=hour*3600L;
epoch +=minute*60;
epoch +=second;
// epoch -=timezone*3600L; // It's semans to be wrong
// epoch -=timezone*900L;
Serial.print(F("POSIX time:"));
Serial.println(epoch);
posix = (float)epoch;
}
et voici ce que ca m’affiche
POSIX time:1482529805
POSIX:1482529792.00
Maintenant je dois traiter 1482529805, qui est un float, pour avoir
1482529805000, mais en double et sans . ou décimal
Pour cela je fait de cette manière
get_posix(); // posix has the value of 1482529805
double posi = (double)posix; // I convert to double
posi = posi*1000; // I mulitplace by 100
Serial.print(F(">>"));
Serial.println(posi); // BUG, it display: >>ovf
Serial.println("");
printFloat(posi,0); // Of course the print is wrong, as the previous is wrong
aJson.addNumberToObject(jobject1, "timestamp", posi); // Here posi must be 1482529805000 without . and decimal
Auroez-vous une idée, comment je peux avoir un double sans . et sans décimal.
En fait le but est de convertir une heure sous ce format
16/12/23,21:50:05+04
en POSIX et à l’heure UTC. Donc pas l’heure local
et ensuite le passer dans cette fonction
aJson.addNumberToObject(jobject1, "timestamp", posi);
qui demande un double dans le dernier paramètre.
Je galère avec ca, alors votre aide me serait ptécieuse
Milles mercis