Retrieve date when application was flashed to a device?


#1

Is there a way to retrieve the date when an application was flashed onto a certain device (Photon) and read that as a Particle.variable()???


#2

@Jan_dM, I put this code in all my devices. It reports the application name, the date and time it was compiled and flashed and the DeviceOS version on the device, all accessible via the Particle.variable() deviceInfo.

// This strips the path from the filename
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)

char gDeviceInfo[120];  //adjust size as required

void setup()
{

    Particle.variable("deviceInfo",gDeviceInfo);
    snprintf(gDeviceInfo, sizeof(gDeviceInfo)
        ,"App: %s, Date: %s, Time: %s, Sysver: %s"
        ,__FILENAME__
        ,__DATE__
        ,__TIME__
        ,(const char*)System.version()  // cast required for String
    );

...
}

#3

Thank you peekay123!
This works fine.


#4

great idea.
I use something similar on Arduino:

  Serial.begin(115200);       // set up Serial library at 9600 bps
  String compiledtime = "";   // I have to use compiledtime because 'complied' is already used for RTC stuff
  String filenm = "";
  filenm = __FILE__ ;
  Serial.println(filenm);

  compiledtime = __DATE__ ;
  compiledtime = compiledtime + " " + __TIME__ ;
  Serial.print("Complied at ");
  Serial.println(compiledtime);

#5

Just a note about performance and memory facilitation of this approach: Creating several intermediate String variables merely for holding and concatenating string literals that are already defined isn’t necessary nor good practice :wink:

  Serial.println("Compiled at " __DATE__ " " __TIME__);

will do the same thing without dynamic memory allocation and intermediate assignments.
In case you really needed a variable compiledtime this would be the alternative approach.

const char* compiledtime = __DATE__ " " __TIME__;

#6

Thanks ScruffR, good point.