Skip to content

ESP reboot on using PSTR() within sprintf function call #484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Jun 29, 2015 · 3 comments
Closed

ESP reboot on using PSTR() within sprintf function call #484

ghost opened this issue Jun 29, 2015 · 3 comments

Comments

@ghost
Copy link

ghost commented Jun 29, 2015

This results into a reboot:

char str[80];
sprintf(str,PSTR("This is a demo: %s for sprintf from flash"),"test123");
Serial.println(str);

Or should I be using sprint_P() but that seems unavailable on ESP.
How to use progmem strings as param to sprintf() ?

@Links2004
Copy link
Collaborator

you mean sprintf_P()?

#define sprintf_P(s, f, ...) sprintf((s), (f), __VA_ARGS__)

@hallard
Copy link
Contributor

hallard commented Jul 7, 2015

@Links2004
Yeah, sprintf_P() would be great but I'm unable to use it (not found at compilation), did I missed one include file ?

@Makuna
Copy link
Collaborator

Makuna commented Jul 10, 2015

You can't use PSTR() with functions that don't end in _P, it won't work correctly.

Links2004 link is incorrect, it should be
https://github.com/esp8266/Arduino/blob/ea302aab05480ad36c076b618abb642b1eb1893b/hardware/esp8266com/esp8266/cores/esp8266/pgmspace.h

Are you including "avr/pgmspace.h"? If so that doesn't work. You need to include just "pgmspace.h".

Further, it looks like sprintf_P is not listed, but snprintf_P is. I will add this, but if you want a work around, you can use snprintf_P instead.

igrr pushed a commit that referenced this issue Jul 13, 2015
@igrr igrr closed this as completed Jul 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants