Skip to content

[script] Credential QR Code and Node Diagram#345

Open
rochaferraz wants to merge 7 commits intoopenthread:mainfrom
rochaferraz:feature/qrcreds-script
Open

[script] Credential QR Code and Node Diagram#345
rochaferraz wants to merge 7 commits intoopenthread:mainfrom
rochaferraz:feature/qrcreds-script

Conversation

@rochaferraz
Copy link
Contributor

This PR introduces two new utility scripts to assist with Thread network provisioning and visualization.

script/qrcreds: A tool for converting Thread Operational Datasets between TLV hex strings and a custom QR code string format (similar to WiFi QR codes). It also supports generating PNG QR code images for easy device provisioning.

script/node_diagram: A visualization tool that parses network traversal JSON data to generate a visual graph of the Thread mesh topology using networkx and matplotlib.

Key Features:

QR Code Generation: Create THREAD:S:... MeCard-like QR Strings and PNGs from a dataset TLV.
Credential Parsing: Decode scanned QR strings back into raw TLV hex for use with the commissioner.
Network Visualization: Visualize the parent-child and router-neighbor relationships within the Thread mesh.

Usage Examples:

Generate a QR code from a TLV dataset:

./script/qrcreds --hex <TLV_HEX_STRING> --qrcode my_network.png

Parse a QR payload string:

Visualize a mesh from traverse_output.json:

./script/node_diagram traverse_output.json

@rochaferraz
Copy link
Contributor Author

/gemini review

@gemini-code-assist
Copy link

Summary of Changes

Hello @rochaferraz, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances Thread network management by introducing two new Python utility scripts. One script streamlines the provisioning process by enabling the conversion of Thread operational datasets into a QR code format, facilitating quick device setup and credential sharing. The other script provides a powerful visualization tool, allowing users to graphically inspect the topology of a Thread mesh network, which is crucial for understanding network structure, identifying relationships between nodes, and assessing link quality.

Highlights

  • Thread Credential QR Code Utility: A new Python script (script/qrcreds) was added to convert Thread Operational Datasets between TLV hex strings and a custom 'THREAD:' QR code string format. It also supports generating PNG QR code images for easy device provisioning.
  • Thread Network Visualization Tool: A new Python script (script/node_diagram) was introduced to visualize Thread mesh network topology. It parses network traversal JSON data and generates a visual graph using networkx and matplotlib, showing parent-child and router-neighbor relationships with link quality.
  • Credential Parsing and Generation: The qrcreds script allows both generating 'THREAD:S:...' MeCard-like QR strings and PNGs from a dataset TLV, and decoding scanned QR strings back into raw TLV hex for use with a commissioner.
  • Comprehensive Testing for QR Credential Script: Unit tests (script/test_qrcreds.py) were added to ensure the correctness of the qrcreds script, covering basic conversions, round-trip functionality, and error handling for invalid inputs.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • script/node_diagram
    • Added a new script for Thread mesh network visualization.
  • script/qrcreds
    • Added a new script for Thread credential QR code generation and parsing.
  • script/test_qrcreds.py
    • Added unit tests for the qrcreds utility.
Activity
  • No human activity (comments, reviews, etc.) has occurred on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces two new utility scripts: qrcreds for converting Thread Operational Datasets to and from QR code strings and generating PNGs, and node_diagram for visualizing Thread mesh networks. The qrcreds script provides useful functionality for provisioning, while node_diagram offers a clear visual representation of network topology. The test_qrcreds.py file adds unit tests for the qrcreds script, which is a good practice. Overall, the new scripts add valuable tools for Thread network management and visualization.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces two useful utility scripts: qrcreds for handling Thread credential QR codes and node_diagram for visualizing the mesh network. The code is well-structured and includes tests for qrcreds.

My review focuses on improving the command-line interface behavior of these scripts. I've suggested changes to ensure error messages are consistently sent to stderr, which is a standard practice that improves usability in shell pipelines. I also recommended adding a warning for malformed input in qrcreds to make it more robust and user-friendly.

rochaferraz and others added 6 commits February 23, 2026 08:56
- Align TLV type codes with MeshCoP standard:
  - Channel: 0x01 -> 0x00
  - PAN ID: 0x02 -> 0x01
  - Ext PAN ID: 0x03 -> 0x02
  - Network Name: 0x04 -> 0x03
  - PSKc: Added as Type 0x04
  - Network Key: 0x05 (Unchanged)
- Add optional fields to QR format:
  - Border Agent ID (B)
  - e-PSKc (R)
  - e-PSKc Expiry (X)
- Make PAN ID or Ext PAN ID mandatory in QR code.
- Canonicalize Channel TLV to compact 1-byte format where possible.
- Update unit tests to reflect new TLV mappings and verify PSKc round trip.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
- Replace sys.exit(1) with ValueError/RuntimeError in core functions:
  - tlv_to_qr: Raises ValueError on invalid hex.
  - qr_to_tlv: Raises ValueError on invalid start prefix.
  - generate_png: Raises RuntimeError if qrcode lib is missing.
  - qr_to_tlv: Prints stderr warning for malformed tokens instead of silent continue.
- Centralize exception handling in main().
- Update unit tests:
  - Verify ValueError is raised instead of SystemExit.
  - Add test_channel_consistency for compact/standard TLV canonicalization.
  - Add test_malformed_token_warning coverage.
@rochaferraz rochaferraz marked this pull request as ready for review February 25, 2026 21:18
args = parser.parse_args()

# Pass the filepath argument into the function
generate_mesh_visualization(args.filepath) No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add a newline at the end of the file

Wi-Fi network credentials ("WIFI:").

Format Structure:
THREAD:S:<Network Name>;P:<Network Key>;I:<PAN ID>;E:<Ext PAN ID>;C:<Channel>;B:<Border Agent ID>;K:<PSKc>;R:<e-PSKc>;X:<e-PSKc Expiry>;;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This format is a bit complicated and not easy to extend in the future.

What about having just the operational dataset TLV hex string? E.g. THREAD:0e08000000000001000000030000104a0300000e35060004001fffe0020815aacecfc1bb71e90708fdb6944646f04bcd0510d81a7de488e95f599c9705122961431b030f4f70656e5468726561642d3064396501020d9e0410c0c06aff5e80f06acbc6054a6201d3410c0402a0f7f8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants