What program is in my Photon? Is the filename uploaded to it?

I’ve had and programmed Particle Photons (and love them), and now own some of the mesh products.

  1. If I’m using the web IDE, is there a way to know which program was uploaded to a an old Photon? - one that you don’t remember what’s on it and you plug it in to your computer?
  2. Sure, there’s output to look for at the pins or the serial output, but barring that, is the name of the file that was uploaded to it available in memory?

If the answer is no, then I just realized what might be a good “best practice”: upload a string variable containing the filename to the protected memory, and make a program that queries that.

  1. Has anyone done that?

Thanks in advance!
I’ve decoded your odor.


I have used this technique with other platforms outside of Particle.

You can either do something simple like store the name of the source file in EEPROM. Or, if you want, you can add additional metadata, such as:

  • description
  • version
  • date of last modification

I guess it depends on whether or not you’re using EEPROM for other purposes. Perhaps we could, as a community, come up with a “standard” definition of what we want to store about the average program. You could either store it starting at location 0, or if you wanted to be able to use EEPROM for other reasons, perhaps you start writing at a certain offset (this would depend of course, on the size of EEPROM for the give platform).

1 Like

Not sure if there is a built-in option, but you could put

Particle.variable("program", __FILE__);

in the setup() of every program

1 Like

@peekay123 introduced me to this concept recently of defining a Particle.variable() named “version”. Every time you flash new code, you increment the version number. This gives you a method to verify what version is on the device by querying the variable. It’s as easy as going to console.particle.io, getting into the device page and retrieving the “version” variable. It’s also a simple method to verify the device is online and communicating to the cloud. Works great on Mesh devices and I would imagine Gen 2 devices as well.


I have some example code here:

1 Like

@OdorDecoder, I use a Particle.variable to report some details on what is running on a given device:

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

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

void setup() {


	snprintf(gDeviceInfo, sizeof(gDeviceInfo)
          ,"App: %s, Date: %s, Time: %s, Sysver: %s
          ,(const char*)System.version()  // cast required for String

This produces, for example, the following string when the variable is queried:
App: MarcoPolo.ino, Date: Dec 14 2018, Time: 17:38:07, Sysver: 0.8.0-rc.26

The Date and Time are the compile date and time.


@peekay123 Funny, I was just working on the same issue. Here is what I wrote:

char sourceFilename[64];

strncpy(sourceFilename, __FILE__, sizeof(sourceFilename)-1);
Serial.printlnf("Source filename: %s", String(sourceFilename).substring(11).toUpperCase().c_str());

@syrinxtech, I try to avoid using String as much as possible :wink:

1 Like

I agree totally. That was my first whack. I do like the strrchr() better.


I ended up with this:

    char *fn = strrchr(__FILE__, '/') + 1;
    Serial.printf("Source file: %s\n", fn);