module
Matter::SetupPayload
Overview
SetupPayload handles encoding and decoding of Matter onboarding payloads
Matter devices use two types of setup codes:
- Manual Pairing Code: 11-digit decimal code (formatted as xxxx-xxx-xxxx)
- QR Code: Longer base38-encoded string with additional device information
Manual Pairing Code Format (Matter Core Spec ยง 5.1.4.1):
- Bits 0-26: Setup PIN Code (27 bits)
- Bits 27-38: Discriminator (12 bits)
- Bit 39: Check digit (4 bits, Verhoeff algorithm)
The 11-digit code is computed as: (discriminator << 27) | PIN Then the Verhoeff check digit is appended.
Defined in:
matter/setup_payload.crClass Method Summary
-
.default_pin : UInt32
Generate a default PIN for testing/examples Returns a valid PIN that's easy to remember
-
.format_manual_code(code : String) : String
Format an 11-digit code as xxxx-xxx-xxxx
-
.generate_manual_code(discriminator : UInt16, pin : UInt32) : String
Generate a manual pairing code from discriminator and PIN
-
.parse_manual_code(formatted_code : String) : Tuple(UInt16, UInt32)
Parse a formatted manual code back to discriminator and PIN
Class Method Detail
Generate a default PIN for testing/examples Returns a valid PIN that's easy to remember
Generate a manual pairing code from discriminator and PIN
@param discriminator Device discriminator (12-bit value, 0-4095) @param pin Setup PIN code (27-bit value, 1-99999998, excluding invalid PINs) @return 11-digit manual pairing code string (formatted as xxxx-xxx-xxxx)
Parse a formatted manual code back to discriminator and PIN
Note: Due to the simplified encoding (using modulo to fit in 10 digits), parsing may not perfectly round-trip for all discriminator/PIN combinations. This is sufficient for device commissioning where the code is generated and used immediately, but a full implementation should use the Matter spec's chunked encoding for perfect round-trip capability.
@param formatted_code Manual code in xxxx-xxx-xxxx format @return Tuple of {discriminator, pin}