0

With ESP32 being so plentiful here (3 more for Christmas) I am at a loss to determine which sketch I used for a particular unit. Has anyone devised a record keeping scheme or even a serial monitor feedback with the sketch details available when plugged back in to the PC?

2
  • What information do you want to see there exactly? You could just do a Serial print with some custom message (defined by you) inside setup(). Is that what you want?
    – chrisl
    Dec 26, 2023 at 10:30
  • I set up a precompile trigger that will run a shell script that grabs the current git hash and puts it in a file as a #define. From my sketch I print that. Then I know which file and which version is loaded.
    – Delta_G
    Dec 26, 2023 at 16:54

2 Answers 2

2

Early in setup() I print one line to the terminal with the .ino file's name, revision, and date. I keep all projects under source-code control which maintains that line without any effort from me, as long as I've included the small snippet of data and and the Serial.println() call to print it.

Update:

Can you show some code how you include the automatic revision identification into the Arduino Build Chain?

Here's an example. Note that the build-chain isn't modified; everything happens in the source code, RCS, in my case. You'll probably have to tweak the keyword that gets the revision data, ($Id$ in RCS) for whatever source control you use. If you aren't using source control, you could print the compile-time macros suggested by @DataFiddler.

/*
 * Macro to tell ::println() & family to expact a pointer to Flash memory
 * #define this in your library's local.h file, or where ever you'd 
 * put your personal, site-unique, or non-public macros like your 
 * WiFi password:
 * 
 * #define FLSTR_HLP(str) (const __FlashStringHelper *)str
 * (Look up __FlashStringHelper for more information)
 * 
 */
// ----------------------------------
// Your .ino file would start here:

#include <local.h>                        // gets the above #define

// Define one of these in each .ino file:
// const char IdString[] PROGMEM = $Id$
// RCS expands or updates it to something like this,
//  every time you check out any version:
//  (Other source control systems will have similar facilities)
const char IdString[] PROGMEM = "$Id: HowTo_IdString.ino,v 1.1 2023-12-26 18:16:06-05 jrobert Exp $";   // def an IdString in Flash



void setup() {
   Serial.begin(115200);
   Serial.print("");
   Serial.println(FLSTR_HLP(IdString));   // prints the IdString from Flash

   // .. more setup ..
}

void loop() {
   Serial.print(F("Run time: "));
   Serial.println(millis());
   delay(5000);
}
2
  • 1
    Interesting. Can you show some code how you include the automatic revision identification into the Arduino Build Chain?
    – PMF
    Dec 26, 2023 at 21:27
  • 1
    Serial.println(__DATE__); Serial.println(__TIME__); shows compilation date and time. Should be close to source file save time. Dec 26, 2023 at 21:35
0

If you want just a simple way of identification, use some of the compiler's predefined macros* as automagic source of information:

void setup() {
  while (!Serial);
  Serial.begin(115200);
  Serial.print("(");
  Serial.print(__VERSION__);
  Serial.print(") ");
  Serial.print(__FILE__);
  Serial.print(": ");
  Serial.print(__DATE__);
  Serial.print(", ");
  Serial.println(__TIME__);
}

void loop() {
}

The output of the sketch is:

(7.3.0) /home/XXXXXXXX/name_of_sketch.ino: Dec 27 2023, 23:03:58

*) In my case (Arduino IDE version 1.8.19) the version of G++ is 7.3.0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.