Skip to content

Commit

Permalink
Added the support for onboarding paylaod in factory script
Browse files Browse the repository at this point in the history
  • Loading branch information
shripad621git committed Jan 9, 2024
1 parent e241e32 commit a9d167e
Showing 1 changed file with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions scripts/tools/generate_esp32_chip_factory_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
CHIP_TOPDIR = os.path.dirname(os.path.realpath(__file__))[:-len(os.path.join('scripts', 'tools'))]
sys.path.insert(0, os.path.join(CHIP_TOPDIR, 'scripts', 'tools', 'spake2p'))
from spake2p import generate_verifier # noqa: E402 isort:skip
sys.path.insert(0, os.path.join(CHIP_TOPDIR, 'src', 'setup_payload', 'python'))
from generate_setup_payload import CommissioningFlow, SetupPayload # noqa: E402 isort:skip

if os.getenv('IDF_PATH'):
sys.path.insert(0, os.path.join(os.getenv('IDF_PATH'),
Expand All @@ -48,11 +50,11 @@

TOOLS = {}


FACTORY_PARTITION_CSV = 'nvs_partition.csv'
FACTORY_PARTITION_BIN = 'factory_partition.bin'
NVS_KEY_PARTITION_BIN = 'nvs_key_partition.bin'
ESP_SECURE_CERT_PARTITION_BIN = 'esp_secure_cert_partititon.bin'
ONBOARDING_DATA_FILE = 'onboarding_codes.csv'

FACTORY_DATA = {
# CommissionableDataProvider
Expand Down Expand Up @@ -602,6 +604,12 @@ def any_base_int(s): return int(s, 0)
help='Do not generate the factory partition binary')
parser.add_argument('--output_dir', type=str, default='bin', help='Created image output file path')

parser.add_argument('-cf', '--commissioning-flow', type=any_base_int, default=0,
help='Device commissioning flow, 0:Standard, 1:User-Intent, 2:Custom. \
Default is 0.', choices=[0, 1, 2])
parser.add_argument('-dm', '--discovery-mode', type=any_base_int, default=1,
help='Commissionable device discovery networking technology. \
0:WiFi-SoftAP, 1:BLE, 2:On-network. Default is BLE.', choices=[0, 1, 2])
parser.set_defaults(generate_bin=True)

return parser.parse_args()
Expand Down Expand Up @@ -633,11 +641,43 @@ def set_up_out_dirs(args):
os.makedirs(args.output_dir, exist_ok=True)


def generate_onboarding_data(args):
if (args.vendor_id and args.product_id):
payloads = SetupPayload(args.discriminator, args.passcode, args.discovery_mode, CommissioningFlow(args.commissioning_flow),
args.vendor_id, args.product_id)
else:
payloads = SetupPayload(args.discriminator, args.passcode, args.discovery_mode, CommissioningFlow(args.commissioning_flow))

logging.info('Discovery mode' + str(args.discovery_mode))
chip_qrcode = payloads.generate_qrcode()
chip_manualcode = payloads.generate_manualcode()
# ToDo: remove this if qrcode tool can handle the standard manual code format
if args.commissioning_flow == CommissioningFlow.Standard:
chip_manualcode = chip_manualcode[:4] + '-' + chip_manualcode[4:7] + '-' + chip_manualcode[7:]
else:
chip_manualcode = '"' + chip_manualcode[:4] + '-' + chip_manualcode[4:7] + '-' + chip_manualcode[7:11] + '\n' + \
chip_manualcode[11:15] + '-' + chip_manualcode[15:18] + '-' + \
chip_manualcode[18:20] + '-' + chip_manualcode[20:21] + '"'

logging.info('Generated QR code: ' + chip_qrcode)
logging.info('Generated manual code: ' + chip_manualcode)

csv_data = 'qrcode,manualcode,discriminator,passcode\n'
csv_data += chip_qrcode + ',' + chip_manualcode + ',' + str(args.discriminator) + ',' + str(args.passcode) + '\n'

with open(os.path.join(args.output_dir, ONBOARDING_DATA_FILE), 'w') as f:
f.write(csv_data)


def main():
args = get_args()
set_up_out_dirs(args)
set_up_factory_data(args)
generate_factory_partiton_binary(args)
if (args.discriminator and args.passcode):
set_up_out_dirs(args)
set_up_factory_data(args)
generate_factory_partiton_binary(args)
generate_onboarding_data(args)
else:
logging.info("Please specify discriminator and passcode")


if __name__ == "__main__":
Expand Down

0 comments on commit a9d167e

Please sign in to comment.