-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BouffaloLab]Add generate factory qr code scripts (#28146)
* add factory qr code scripts * remove unused modules * Restyled by autopep8 * remove unused modules --------- Co-authored-by: Restyled.io <[email protected]>
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
bflb-iot-tool>=1.8.0 | ||
jsonschema>=4.4.0 | ||
cbor2>=5.4.3 | ||
ecdsa>=0.18.0 | ||
qrcode==7.4.2 | ||
bitarray==2.6.0 | ||
python_stdnum==1.18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright (c) 2022 Project CHIP Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import argparse | ||
import os | ||
import sys | ||
|
||
try: | ||
import qrcode | ||
from generate_setup_payload import CommissioningFlow, SetupPayload | ||
except ImportError: | ||
SDK_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))) | ||
sys.path.append(os.path.join(SDK_ROOT, "src/setup_payload/python")) | ||
try: | ||
import qrcode | ||
from generate_setup_payload import CommissioningFlow, SetupPayload | ||
except ModuleNotFoundError or ImportError: | ||
no_onboarding_modules = True | ||
else: | ||
no_onboarding_modules = False | ||
else: | ||
no_onboarding_modules = False | ||
|
||
|
||
def allow_any_int(i): return int(i, 0) | ||
|
||
|
||
def get_args(): | ||
parser = argparse.ArgumentParser(description="BouffaloLab QR Code generator tool") | ||
mandatory_arguments = parser.add_argument_group( | ||
"Mandatory keys", "These arguments must be provided to generate QR Code JSON file") | ||
mandatory_arguments.add_argument("--vendor_id", type=allow_any_int, required=True, | ||
help="[int | hex int] Provide Vendor Identification Number") | ||
mandatory_arguments.add_argument("--product_id", type=allow_any_int, required=True, | ||
help="[int | hex int] Provide Product Identification Number") | ||
mandatory_arguments.add_argument("--discriminator", type=allow_any_int, required=True, | ||
help="[int] Provide BLE pairing discriminator. \ | ||
A 12-bit value matching the field of the same name in \ | ||
the setup code. Discriminator is used during a discovery process.") | ||
mandatory_arguments.add_argument("--pincode", type=allow_any_int, required=True, | ||
help=("[int | hex] Default PASE session passcode. " | ||
"(This is mandatory to generate QR Code).")) | ||
mandatory_arguments.add_argument("-o", "--output", type=str, required=True, | ||
help="Output path to store .json file, e.g. my_dir/output.json") | ||
return parser.parse_args() | ||
|
||
|
||
def generate_qrcode_data(args): | ||
if no_onboarding_modules is False: | ||
setup_payload = SetupPayload(discriminator=args.discriminator, | ||
pincode=args.pincode, | ||
rendezvous=2, # fixed pairing BLE | ||
flow=CommissioningFlow.Standard, | ||
vid=args.vendor_id, | ||
pid=args.product_id) | ||
with open(args.output[:-len(".json")] + ".txt", "w") as manual_code_file: | ||
manual_code_file.write("Manualcode : " + setup_payload.generate_manualcode() + "\n") | ||
manual_code_file.write("QRCode : " + setup_payload.generate_qrcode()) | ||
qr = qrcode.make(setup_payload.generate_qrcode()) | ||
qr.save(args.output[:-len(".json")] + ".png") | ||
else: | ||
print("Please install it with all dependencies: pip3 install -r ./scripts/setup/requirements.bouffalolab.txt from the Matter root directory") | ||
|
||
|
||
def main(): | ||
args = get_args() | ||
generate_qrcode_data(args) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |