Set up of the GRL Thread Test Harness and the OpenThread Harness Automation Tool
for use with the OpenThread Border Router (OTBR) Device Under Test (DUT) is the
same as the [Certification Automation Setup
guide](https://openthread.io/certification/automation-setup). Use that guide in conjunction with the
changes detailed here.

For an NCP design like OTBR, OpenThread provides an [`OpenThread_WpanCtl.py`
example Thread Host Control Interface
(THCI)](https://github.com/openthread/openthread/tree/master/tools/harness-thci/OpenThread_WpanCtl.py)
that allows the Test Harness to control the NCP. There are two connection modes
for an NCP device:

- Using a serial port connection (recommended for use of the Test Harness's auto discovery feature)
- Using an SSH connection

Unless otherwise noted, all installation and configuration steps below occur on
the Windows machine running the GRL Test Harness software, which should be
installed before continuing.

## Copy THCI support files

Make sure you have the latest version of THCI on the Windows machine. Clone the
OpenThread repository, or if you already have, switch it to the `main` branch:

    git clone https://github.com/openthread/openthread

    cd openthread

    git checkout main

Copy the following files from
[`/tools/harness-thci`](https://github.com/openthread/openthread/tree/master/tools/harness-thci)
in the cloned OpenThread repository to the specified directories on the Windows
machine:

| Source file | Copy to directory |
|---|---|
| `deviceInputFields.xml` | `C:\GRL\Thread1.1\Web\data\` |
| `OpenThread_WpanCtl.py` | `C:\GRL\Thread1.1\Thread_Harness\THCI\` |
| `OpenThread_WpanCtl.png` | `C:\GRL\Thread1.1\Web\images\` |

## Set up connection type

For Test Harness control of the NCP, set up either a serial port connection or
an SSH connection.

> [!CAUTION]
> Only one of these connection types should be used to control the NCP. **Do not use both connection types at the same
> time.**

### Serial port connection (recommended)

On the Raspberry Pi 3B (RPi3B), enable the serial port and login shell:

1. Enter the configuration menu:

       sudo raspi-config

2. In the configuration menu, select **5 Interfacing Options**.
3. In the Interfacing Options menu, select **P6 Serial Enable/Disable**.
4. Restart the RPi3B.

On the Windows machine running the Test Harness:
![OTBR FT232 Connection](https://openthread.io/static/certification/images/otbr-cert-pi-ft232-serial-conn.png)

1. Download and install the [FT232
   driver](https://www.ftdichip.com/Drivers/VCP.htm).
2. Connect the FT232 USB to UART adapter to a USB slot on the Windows machine.
3. Set the voltage jumper on the FT232 to 3.3V.
4. Connect the FT232 to the RPi3B using the following pins and Dupont lines:

   | RPi3B Pin | FT232 Pin | Dupont Line |
   |---|---|---|
   | Pin6 | GND | White |
   | Pin8 | RXD | Yellow |
   | Pin10 | TXD | Red |

5. Once connected, restart the Windows machine.
6. Find the device serial port hardware identifier, using the Python pySerial module:
   1. [Install pySerial](https://pythonhosted.org/pyserial/pyserial.html) on the Windows machine.
   2. Use Python on the Windows command line to enumerate all hardware identifiers (VID and PID) for devices connected to the machine. In this output, one NCP device is connected, with an identifier of `VID_0403+PID_6001`.

          python -m serial.tools.list_ports -v
          COM10
              desc: USB Serial Port (COM10)
              hwid: FTDIBUS\VID_0403+PID_6001+AL01WOSZA\0000

   3. If you know the COM port already, you can use a different command. For example, if the COM port is `COM10`:

          python -c "import serial.tools.list_ports;print [ports[2] for ports in serial.tools.list_ports.comports() if ports[0] == 'COM10']"
          ['FTDIBUS\VID_0403+PID_6001+AL01WP6MA\0000']

7. Update the Golden Device list:
   1. Open `C:\GRL\Thread1.1\Config\Configuration.ini`
   2. Add an **OpenThread_WpanCtl** grouping to the `GoldenDeviceHardwareIds` array with the VID and PID of the device(s):

      ```
      GoldenDeviceHardwareIds = {
      'NXP': ['VID:PID=1FC9:0300','VID:PID=15A2:0300','VID:PID=1366:1015'], 
      'SiLabs': 'VID:PID=10C4:8A5E', 
      'ARM': 'VID:PID=0D28:0204', 
      'OpenThread':['VID:PID=10C4:EA60', 'VID:PID=1915:CAFE'], 
      'OpenThread_WpanCtl':['VID_0403+PID_6001']}
      ```

Once all configuration is complete:

1. Start the GRL Test Harness.

   > [!NOTE]
   > **Note:** If the device is connected to the Windows Machine prior to starting the GRL Test Harness software, as described in these procedures, the Test Harness should automatically discover the device. If the device is connected after starting the Test Harness, you might have to add it manually as noted in the next step.  
   >
   > We recommend not starting the Test Harness until the device is connected and all setup and configuration up to this point is complete.

2. On the **Configure Test Bed** page, the device/port now appears as an OT NCP
   device.

   If the DUT is not listed in the **Test Bed** section after the Test Harness
   is started, manually add it by dragging the **OpenThread WpanCtl:
   wpantund+NCP** device from the **Supported Hardware** section to the **Test
   Bed** section. After dragging:
   1. Ensure the correct **Serial Line** (COM port) and **Speed** (baud rate) values are populated.
   2. Click the arrow button below the **Speed** field to establish the serial connection between the Test Harness and the OT NCP device.
3. Select the **Enable Auto DUT Device Selection** checkbox below the Supported
   Hardware list.

4. Select the **Set as DUT** radio button under the target device/port to set
   the OT NCP device as the DUT.

[![OTBR Certification SSH](https://openthread.io/static/certification/images/otbr-cert-harness.png)](https://openthread.io/static/certification/images/otbr-cert-harness.png)

### SSH connection

> [!NOTE]
> **Note:** To use SSH, the RPi3B must be on the same LAN as the Windows machine.

On the RPi3B, enable SSH:

1. Enable the SSH service on boot:

       sudo systemctl enable ssh

2. Start the SSH service:

       sudo systemctl start ssh

To enable SSH on a headless RPi3B, see Step 3 of the [Raspberry Pi SSH
documentation](https://www.raspberrypi.org/documentation/remote-access/ssh/).

On the Windows machine running the Test Harness:

1. Install Paramiko for GRL's Python environment:

       cd C:\GRL\Python2.7

       python -m pip install --upgrade pip

       python -m pip install paramiko

2. Start the GRL Test Harness.
3. On the **Configure Test Bed** page, drag the **OpenThread WpanCtl SSH:
   wpantund+NCP** device from the **Supported Hardware** section to the **Test Bed** section.
4. Populate the **IP addr** with 192.168.1.100 and **PORT** with 22 for the device.
5. Click the arrow button below the **PORT** field to establish an SSH connection between the Test Harness and the OT NCP device.

[![OTBR Certification SSH](https://openthread.io/static/certification/images/otbr-cert-harness-ssh.png)](https://openthread.io/static/certification/images/otbr-cert-harness-ssh.png)

## Automation Setup

See the [Install](https://openthread.io/certification/automation-setup#install) and
[Configure](https://openthread.io/certification/automation-setup#configure) steps from the
Certification Automation Setup guide for instructions on how to set up the
Harness Automation Tool.

## Run test cases

See [Running Certification Test Cases](https://openthread.io/certification/test-cases) to learn how
to run certification test cases on the OTBR DUT.

## Troubleshooting

### Device reboots

If you need to reboot the RPi3B, close the Test Harness software and wait at
least 20 seconds after the reboot is complete to start the Test Harness again.

### Test Harness fails to discover Border Router

When using a serial port connection, the Test Harness may not discover the
Border Router. If this is the case:

1. Check whether a Shell login works for the serial port, using a tool like [PuTTY](https://www.putty.org/).
   1. Use the COM port for the FT232 device and a speed (baud rate) of 115200.
   2. If the login fails, reboot all devices and try it again.
2. On the RPi3B, check the status of `wpantund`:

       sudo service wpantund status

   If the status is "abnormal":
   1. Make sure the nRF52840 NCP board is mounted:

          ls /dev/tty*
          /dev/ttyACM0

   2. Validate that this port matches the `wpantund` configuration:

      ```
      // default value in '/etc/wpantund.conf'
      Config:NCP:SocketPath "/dev/ttyACM0"
      ```
   3. Restart `wpantund`:

          sudo service wpantund restart