sprintf(buf, "%s", (const char*)System.version());
// or
sprintf(buf, "%s", System.version().c_str());
Yup, double underscores. I’m not sure but __FILENAME__ might be just the file. I’ll have to check GCC compiler variables. Doesn’t seem to be in the standard.
Hmmmm…well…I’m using Particle Dev. Perhaps that’s at the root of the difference. With out that string function, I’m getting a verrrrrrry long fully-qualified app name.
Yep, that was the difference. In Dev, you get, “//src/appName.cpp” after the long 60 character string, but Build doesn’t have that “//src” in there. Good to know that.
so…what we need to find is the string function that allows us to find the last “/” in the filename and that should do it for both avenues. I thought I had it…but not yet.
@ctmorrison, that buf was just an example
The maximum conciseness would be with this
snprintf(gDeviceInfo, sizeof(gDeviceInfo)
,"Application: %s, Date: %s, Time: %s, System firmware: %s, SSID: %s, RSSI: %i"
,strstr(__FILE__,"//")
,__DATE__
,__TIME__
,(const char*)System.version() // cast required for String
,(const char*)WiFi.SSID() // cast not required but always safe when in doubt if String or char*
,WiFi.RSSI()
);
(I also added the safety check to obey the buffer boundaries)
The above example also illustrates why I prefer (const char*)stringObject over the widely used alternative stringObject.c_str() since the former always works while the other would throw an error on a non-String.
Since you are looking for the last occurance of a single character you can use strrchr()
(Oops, didn’t see all these posts in between pointing out strrchr() already - got a rather slow net here)
@peekay123 Are you getting the short file name (just “projectName.cpp”), or are you getting the whole long version? His code works for me, but if I make it get the whole output of __FILE__, then it stops after the time value due to running out of room in the char array.
@peekay123 hmm… that’s weird. I just re-copied and pasted his code, to make sure mine was identical to his, and it worked fine (Photon, checked by Serial print and variable GET through CLI).
Application: epromlengthproblem.cpp, Date: Feb 18 2017, Time: 02:21:09, System firmware: 0.6.0, SSID: Ric's WiFi, RSSI: -50