I am logging binary data to my SD. I log a datetime object of type 'tm', which is 36 bytes on ESP32. When I create a datetime of type 'tm' on linux it is 56 bytes.
ESP32 write tm to SD: [tm datetime = 36 bytes]
time_t t = std::time(nullptr);
tm datetime = *std::localtime(&t);
uint16_t t = file.write((const uint8_t *)&datetime, sizeof(datetime)); // ==36 bytes.
PC [tm datetime = 56 bytes] (compiled using g++ on linux 64)
tm datetime;
std::ifstream fileStream(filename, std::ios::binary);
fileStream.read((char *)&datetime, sizeof(datetime));
tm is defined in time.h:
struct tm
{
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
#ifdef __TM_GMTOFF
long __TM_GMTOFF;
#endif
#ifdef __TM_ZONE
const char *__TM_ZONE;
#endif
};
My tm struct doesn't have the 'tm_gmtoff' or 'tm_zone', even if it had it wont add up to 56 bytes.
How can my tm be 56 bytes on my PC? If someone has a better way to log a datetime object, without this issue, let me know.
sizeof(int)on arduino (AVR) is 2, on most other platforms its 4.date +'%FT%T%:z'. If you really need binary, logtime_trather thanstrcut tm.strcut tmis implementation dependent. In contrast,time_tis usually a simple integer, with very little variations across implementations: either 32 or 64 bits, and maybe a different epoch (which is fixed by simply adding a constant).