Hi
I have recently reinstalled my Arduino IDE 1.8.16 (Mac)
It fetched ESP8266 Boards Version3.0.2
My sketch compiled error-free, but crashed on a Wemos D1 mini.
I narrowed down the error to:
getEpoch(); // writes the Epoch (Numbers of seconds till 1.1.1970...
getTimeData(); // breaks down the Epoch into discrete values.
sprintf(charbuff, "Now is %02d:%02d:%02d. The Epoch is: %10lu\r\nDate is %s, %02d %s %04d", Hour, Minute, Second, Epoch, DayName, Day, MonthName, Year);
Console3.println(charbuff);
Without printing the Epoch with %10lu it worked.
I can far remember having read something with lu beeing non-standard ?
Is it a bug or not?
if not, what is the replacement for lu?
Charbuff is an array of 80 bytes,
Epoch inherits from time_t,
Hour, Minute, Second, Day, Year integers,
Dayname and Monthname arrays of 12 bytes.
The routine runs upon initializing, just after Wifi connection and NTP sync.
My sketch uses 486129 bytes (46%) of program storage space. Maximum is 1044464 bytes.
Global variables use 40304 bytes (49%) of dynamic memory, leaving 41616 bytes for local variables. Maximum is 81920 bytes.
So ii won't run out of memory.
So, if lu is acceptable, it's a bug.
It worked with the ESP8266 lib V2.7.4.
Without this lu part of the sprintf, it works also.
The case should be clear enough?
Your source code really was the ask . It might crash elsewhere.
Possibly 79 bytes not enough for this
Now is %02d:%02d:%02d. The Epoch is: %10lu\r\nDate is %s, %02d %s %04d
Use snprintf() and see if you still have the crash.
The fact that it crashes depends on what’s in memory after the string buffer which can very depending on how it’s compiled so can work with luck or have silent damage
void setup() {
char charbuff[80];
memset (charbuff, '\0', 80);
Serial.begin(115200);
int Hour, Minute, Second,Day, Year;//32 bit integers on esp8266
long int Epoch; //64 bit for extended epoch
Hour = 12;
Minute = 30;
Second = 45;
Epoch = 1234567890;
Day =1;
Year = 2022;
char DayName[] = "Sunday";
char MonthName[] = "May";
delay(5000);
sprintf(charbuff, "Now is %02d:%02d:%02d. The Epoch is: %10lu\r\nDate is %s, %02d %s %04d", Hour, Minute, Second, Epoch, DayName, Day, MonthName, Year);
Serial.println(strlen(charbuff));
Serial.println(charbuff);
}
void loop() {
// put your main code here, to run repeatedly:
}
11:06:56.772 -> 70
11:06:56.772 -> Now is 12:30:45. The Epoch is: 1234567890
11:06:56.817 -> Date is Sunday, 01 May 2022
I am currently updating Github and will provide the whole code soon (quite a lot...)
79 bytes is more than enough, it worked previously.
The output is:
Now is 20:10:03.
[ Epoch = 10 chars for Epoch ]
Date is Sunday, 01 May 2022
so ~just 60 chars.
OK if you say so (I count 26 just for the epoch message)
did not know exactly your text representation (you said 12 bytes for month and days so could be padded there too) but you are the one with the code