1*cfb92d14SAndroid Build Coastguard Worker# OpenThread Control Interface 2*cfb92d14SAndroid Build Coastguard Worker 3*cfb92d14SAndroid Build Coastguard WorkerThe OpenThread Control Interface (OTCI) is a library which provides uniform python interfaces to connect and control various kinds of devices running OpenThread. 4*cfb92d14SAndroid Build Coastguard Worker 5*cfb92d14SAndroid Build Coastguard Worker## Supported device types 6*cfb92d14SAndroid Build Coastguard Worker 7*cfb92d14SAndroid Build Coastguard Worker- OpenThread CLI 8*cfb92d14SAndroid Build Coastguard Worker - SOC device via Serial 9*cfb92d14SAndroid Build Coastguard Worker- OpenThread NCP (limited support via [pyspinel](https://pypi.org/project/pyspinel/)) 10*cfb92d14SAndroid Build Coastguard Worker - SOC device via Serial 11*cfb92d14SAndroid Build Coastguard Worker- [OpenThread Border Router](https://github.com/openthread/ot-br-posix) 12*cfb92d14SAndroid Build Coastguard Worker - OTBR device via SSH 13*cfb92d14SAndroid Build Coastguard Worker 14*cfb92d14SAndroid Build Coastguard Worker## Example 15*cfb92d14SAndroid Build Coastguard Worker 16*cfb92d14SAndroid Build Coastguard Worker```python 17*cfb92d14SAndroid Build Coastguard Workerimport otci 18*cfb92d14SAndroid Build Coastguard Worker 19*cfb92d14SAndroid Build Coastguard Worker# Connect to an OTBR device via SSH 20*cfb92d14SAndroid Build Coastguard Workernode1 = otci.connect_otbr_ssh("192.168.1.101") 21*cfb92d14SAndroid Build Coastguard Worker 22*cfb92d14SAndroid Build Coastguard Worker# Connect to an OpenThread CLI device via Serial 23*cfb92d14SAndroid Build Coastguard Workernode2 = otci.connect_cli_serial("/dev/ttyACM0")) 24*cfb92d14SAndroid Build Coastguard Worker 25*cfb92d14SAndroid Build Coastguard Worker# Start node1 to become Leader 26*cfb92d14SAndroid Build Coastguard Workernode1.dataset_init_buffer() 27*cfb92d14SAndroid Build Coastguard Workernode1.dataset_set_buffer(network_name='test', network_key='00112233445566778899aabbccddeeff', panid=0xface, channel=11) 28*cfb92d14SAndroid Build Coastguard Workernode1.dataset_commit_buffer('active') 29*cfb92d14SAndroid Build Coastguard Worker 30*cfb92d14SAndroid Build Coastguard Workernode1.ifconfig_up() 31*cfb92d14SAndroid Build Coastguard Workernode1.thread_start() 32*cfb92d14SAndroid Build Coastguard Workernode1.wait(5) 33*cfb92d14SAndroid Build Coastguard Workerassert node1.get_state() == "leader" 34*cfb92d14SAndroid Build Coastguard Worker 35*cfb92d14SAndroid Build Coastguard Worker# Start Commissioner on node1 36*cfb92d14SAndroid Build Coastguard Workernode1.commissioner_start() 37*cfb92d14SAndroid Build Coastguard Workernode1.wait(3) 38*cfb92d14SAndroid Build Coastguard Worker 39*cfb92d14SAndroid Build Coastguard Workernode1.commissioner_add_joiner("TEST123",eui64='*') 40*cfb92d14SAndroid Build Coastguard Worker 41*cfb92d14SAndroid Build Coastguard Worker# Start node2 42*cfb92d14SAndroid Build Coastguard Workernode2.ifconfig_up() 43*cfb92d14SAndroid Build Coastguard Workernode2.set_router_selection_jitter(1) 44*cfb92d14SAndroid Build Coastguard Worker 45*cfb92d14SAndroid Build Coastguard Worker# Start Joiner on node2 to join the network 46*cfb92d14SAndroid Build Coastguard Workernode2.joiner_start("TEST123") 47*cfb92d14SAndroid Build Coastguard Workernode2.wait(10, expect_line="Join success") 48*cfb92d14SAndroid Build Coastguard Worker 49*cfb92d14SAndroid Build Coastguard Worker# Wait for node 2 to become Router 50*cfb92d14SAndroid Build Coastguard Workernode2.thread_start() 51*cfb92d14SAndroid Build Coastguard Workernode2.wait(5) 52*cfb92d14SAndroid Build Coastguard Workerassert node2.get_state() == "router" 53*cfb92d14SAndroid Build Coastguard Worker``` 54