Generate device password on build

Hi,

I want to generate a password before the build and then program it into the device

Please give me a hint on how to import a dynamic env variable into my cpp program

Thank you

Edit: I found a way with a py script

[env:uno]
platform = atmelavr
board = uno
framework = arduino
extra_scripts = prebuild.py

#!/usr/bin/env python

import string
import random


def password_generator(size=5, chars=string.digits):
    return ''.join(random.choice(chars) for i in range(size))

print ">>>>>>>> Generating device PIN"
pin = password_generator(5);
print ">>>>>>>> New PIN: " + pin

f = open("src/pin.h", "w")
f.write("String pin = \"" + pin + "\";")

Check Dynamic build flags.

1 Like