Tuesday, August 25, 2020

Build OpenThread Sleepy End Device doorlock prototype to test with Rasperry Pi OpenThread Border Router

The following steps show how to build OpenThread Sleepy End Device doorlock prototype to test with Rasperry Pi OpenThread Border Router

1. Build OpenThread Sleepy End Device doorlock prototype for TI LAUNCHXL-CC26X2R1

1.1 Download/Install TI CCS 10.1 and SIMPLELINK-CC13X2-26X2-SDK v4.20.00.35.

1.2 Import thread door_lock example from C:\ti\simplelink_cc13x2_26x2_sdk_4_20_00_35\examples\rtos\CC26X2R1_LAUNCHXL\thread\door_lock

1.3 Set door_lock as Sleepy End Device from sysconfig.

 

1.4 Add the following codes in tiop_ui.c for providing API to output IPv6 address to UART console.

inline uint16_t Swap16(uint16_t v)
{
    return (((v & 0x00ffU) << 8) & 0xff00) | (((v & 0xff00U) >> 8) & 0x00ff);
}
 

inline uint16_t HostSwap16(uint16_t v)
{
    return Swap16(v);
}

void tiopCUIOutputIp6Address(otIp6Address aAddress)
{
    CUI_statusLinePrintf(
        clientHandle, nwkInfoLine1,
        "[" CUI_COLOR_GREEN "IPv6" CUI_COLOR_RESET "] %s - %x:%x:%x:%x:%x:%x:%x:%x",
        "Addr",
        HostSwap16(aAddress.mFields.m16[0]), HostSwap16(aAddress.mFields.m16[1]),
                HostSwap16(aAddress.mFields.m16[2]), HostSwap16(aAddress.mFields.m16[3]), HostSwap16(aAddress.mFields.m16[4]),
                HostSwap16(aAddress.mFields.m16[5]), HostSwap16(aAddress.mFields.m16[6]), HostSwap16(aAddress.mFields.m16[7]));
}

1.5 Add the following line to expose API tiopCUIOutputIp6Address in tiop_ui.h.

extern void tiopCUIOutputIp6Address(otIp6Address aAddress);

1.6 Add the following line in "case DoorLock_evtKeyRight:..." of processEvent (doorlock.c) to output IPv6 address when right button is pressed.

tiopCUIOutputIp6Address(*(otThreadGetRloc(OtInstance_get())));

1.7 Build and download sleepy door_lock firmware into LAUNCHXL-CC26X2R1.

 

2. Setup OpenThread Border Router and libcoap on Raspberry Pi.

2.1 Refer to this link to setup OpenThread Border Router on Raspberry Pi.

2.2 Run the following command in Raspberry Pi console to setup libcoap.

      sudo apt install autoconf automake libtool
      git clone --depth 1 --recursive -b dtls https://github.com/home-assistant/libcoap.git
      cd libcoap
      ./autogen.sh
      ./configure --disable-documentation --disable-shared --without-debug CFLAGS="-D COAP_DEBUG_FD=stderr"
      make
      sudo make install

3. Use the following commands on Raspberry Pi console and start sleepy door_lock to join thread network. Then, press right button on LAUNCHXL-CC26X2R1 to print IPv6 address of sleepy door_lock.

sudo ot-ctl commissioner start
sudo ot-ctl commissioner joiner add 00124b001ca16238 DRRLCK1

4. Use the following command to request lock state of sleepy door_lock from border router.

coap-client -m get coap://[fd11:1111:1122:0:0:ff:fe00:ec08]/doorlock/lockstate

5. Use the following command to change lock state of sleepy door_lock from border router.

coap-client -m post coap://[fd11:1111:1122:0:0:ff:fe00:ec08]/doorlock/lockstate -e unlock

 


No comments:

Post a Comment