Build Counter to define C++ macro?

Is there any simple way with platformio to have an incremental build counter?

E.g. pio writes an automatically incremented number to an include file, e.g. named buildnumber.h


#define BUILD_NUMBER 12

    so I can include it in my main file to set a unique version number?

e.g. (example is for [Homie]( firmware that is upgradable via [OTA](

    #include "buildnumber.h"
    #define FW_VERSION "0.2."
    const char *__FLAGGED_FW_VERSION = "\x6a\x3f\x3e\x0e\xe1" FW_VERSION BUILD_NUMBER "\xb0\x30\x48\xd4\x1a";

You can do it with python here:
But maybe it makes more sense here: Git - Book

1 Like