-->
Page 1 of 1

Issue with snprintf function in ESP8266

PostPosted: Sat Oct 26, 2019 7:14 am
by Shoeb
Following code doesn't show any compile error. Upload to ESP module is also successful.
But after successful upload, ESP module continues restating.
If I remove snprintf function it is ok.

void html_page(){

int sec = millis() / 1000;
int min1 = sec / 60;
int hr = min1 / 60;

const char dataHTML[]=R"RAW(
<html>
<body>
<p>Uptime: %d:%d:%d</p>
</body>
</html>
)RAW";
snprintf(page,100,dataHTML,sec,min1,hr);
Serial.println(page);
server.send(200, "text/html", page);
}

Re: Issue with snprintf function in ESP8266

PostPosted: Sun Oct 27, 2019 10:32 am
by martinayotte
How did you allocate page variable ?

Re: Issue with snprintf function in ESP8266

PostPosted: Mon Oct 28, 2019 5:08 am
by Shoeb
Tried with all the following ways -
const char* page;
const char page[1000];
char* page;
char page[1000];

Re: Issue with snprintf function in ESP8266

PostPosted: Mon Oct 28, 2019 11:17 am
by RichardS
I would expect page[1000] to work, try commenting out serial.Print