|
| 1 | +### Examples |
| 2 | + |
| 3 | +#### Getting Started |
| 4 | +To start using the library first instantiate the controller. |
| 5 | +```c# |
| 6 | +// Option 1 |
| 7 | +Controller controller = new Controller("Example Matter Fabric"); |
| 8 | + |
| 9 | +// Option 2 |
| 10 | +Controller controller = Controller.Load("example.fabric", "example.key"); |
| 11 | +``` |
| 12 | +_Option 1: Creates a new controller then generates the fabric named "Example Matter Fabric" and the certificates._\ |
| 13 | +_Option 2: Load an existing fabric into a controller._ |
| 14 | + |
| 15 | +#### Example 1: Interviewing the Fabric |
| 16 | +On first startup of a fabric or after a long disconnected period it is a good idea to re-enumerate the fabric. This will interview each node on the fabric for some basic information. |
| 17 | +```c# |
| 18 | +await controller.EnumerateFabric(); |
| 19 | +``` |
| 20 | + |
| 21 | +#### Example 2: Adding Nodes (Commissioning an already commissioned device): |
| 22 | +This example adds a node to our fabric that has already been setup by another device. To commission a node, we need a commissioning payload. This is generated with either an 11/21 digit PIN Code, a QR code or an NFC tag. |
| 23 | +```c# |
| 24 | +// Option 1 |
| 25 | +CommissioningPayload payload = CommissioningPayload.FromPIN("00362159269"); |
| 26 | + |
| 27 | +// Option 2 |
| 28 | +CommissioningPayload payload = CommissioningPayload.FromQR("MT:Y.K9042C00KA0648G00"); |
| 29 | + |
| 30 | +// Option 3 |
| 31 | +CommissioningPayload payload = CommissioningPayload.FromNFC(nfcBytes); |
| 32 | +``` |
| 33 | +_Option 1: Creates a commissioning payload from a PIN Number._\ |
| 34 | +_Option 2: Creates a commissioning payload from a QR Code._\ |
| 35 | +_Option 3: Creates a commissioning payload from an NFC tag._ |
| 36 | + |
| 37 | +Once we have the payload, we can activate commissioning which will automatically search bluetooth and/or the network and setup the device. |
| 38 | + |
| 39 | +```c# |
| 40 | + CommissioningState info = await controller.StartCommissioning(payload); |
| 41 | + await controller.CompleteCommissioning(info); |
| 42 | + controller.Save("example.fabric", "example.key"); |
| 43 | +``` |
| 44 | +_Line 1 Find the device and begin commissioning._\ |
| 45 | +_Line 2 Complete commissioning._\ |
| 46 | +_Line 3 Save the fabric with the certificates for the newly added node._ |
| 47 | + |
| 48 | +#### Example 3: Adding Nodes (Commissioning a New/Reset Device): |
| 49 | +To commission a node, we need a commissioning payload. This is generated with either an 11/21 digit PIN Code, a QR code or an NFC tag. |
| 50 | +```c# |
| 51 | +// Option 1 |
| 52 | +CommissioningPayload payload = CommissioningPayload.FromPIN("00362159269"); |
| 53 | + |
| 54 | +// Option 2 |
| 55 | +CommissioningPayload payload = CommissioningPayload.FromQR("MT:Y.K9042C00KA0648G00"); |
| 56 | + |
| 57 | +// Option 3 |
| 58 | +CommissioningPayload payload = CommissioningPayload.FromNFC(nfcBytes); |
| 59 | +``` |
| 60 | +_Option 1: Creates a commissioning payload from a PIN Number._\ |
| 61 | +_Option 2: Creates a commissioning payload from a QR Code._\ |
| 62 | +_Option 3: Creates a commissioning payload from an NFC tag._ |
| 63 | + |
| 64 | +Once we have the payload, we can activate commissioning which will automatically search bluetooth and/or the network and setup the device. |
| 65 | + |
| 66 | +```c# |
| 67 | + CommissioningState info = await controller.StartCommissioning(payload); |
| 68 | + var result = info.FindWiFi("Linksys-24G")!; |
| 69 | + await controller.CompleteCommissioning(info, result, "password123"); |
| 70 | + controller.Save("example.fabric", "example.key"); |
| 71 | +``` |
| 72 | +_Line 1 Find the device and begin commissioning._\ |
| 73 | +_Line 2 Select a WiFi network out of the networks the device can see. This step can be skipped if the device is already on the network._\ |
| 74 | +_Line 3 Complete commissioning and connect to the provided WiFi network._\ |
| 75 | +_Line 4 Save the fabric with the certificates for the newly added node._ |
| 76 | + |
| 77 | +Alternatively, line 2 can be replaced by selecting a thread network or an ethernet connection. |
0 commit comments