Thursday, December 13, 2018

How to use EmberZNet to do ZCL report

The following steps show you how to use EmberZNet to do ZCL report

Using ZCL_TEMP_MEASUREMENT_CLUSTER_ID to send temperature attribute report as example.

1. Prepare ZCL data buffer with emberAfFillCommandGlobalServerToClientReportAttributes. The buffer format is Attribute ID -> Data type -> Attribute data. For Attribute ID and Attribute data, it's low byte first.

uint8_t buff[5] = {0x00, 0x00, 0x29, 0x05, 0x06};  //Attribute ID (0x0000) -> Data type (0x29) -> Attribute data (0x0605). emberAfFillCommandGlobalServerToClientReportAttributes(ZCL_TEMP_MEASUREMENT_CLUSTER_ID, (uint8_t *) buff, 5);

2. Set source and destination endpoint with emberAfSetCommandEndpoints

emberAfSetCommandEndpoints(1, 1); //endpoint(uint8_t sourceEndpoint, uint8_t destinationEndpoint):

3. Call the following line to do unicast to coordinator

emberAfSendCommandUnicast(EMBER_OUTGOING_DIRECT, 0x0000);


Or call the following line to do unicast using binding address.

emberAfSendCommandUnicastToBindings();

Tuesday, December 4, 2018

How to detect button hold in CC26x2, CC13x0, CC13x2 SDK.

The following steps show you how to detect button hold in CC26x2, CC13x0, CC13x2 SDK. I use zed_switch example to add related code to detect if right button (active-low) is pressed (low status) and hold for 3 seconds.

1. In board_key.c, change Board_PIN_BUTTON1 to use PIN_IRQ_BOTHEDGES

static PIN_Config keyPinTable[] = {
      Board_PIN_BUTTON0 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,
      Board_PIN_BUTTON1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES,
      PIN_TERMINATE /* Terminate list */
    };


2. Add the following red codes in board_key.c

#include
...
UInt32 button_pressed_time=0;
UInt32 button_released_time=0;
static void board_key_keyFxn(PIN_Handle keyPinHandle, PIN_Id keyPinId)
{
    (void)keyPinHandle;

    if(keyPinId == keyButton0)
    {
        keysPressed |= KEY_LEFT;
    }
    else if(keyPinId == keyButton1)
    {
        if(PIN_getInputValue(keyButton1) == false){
            button_pressed_time=Clock_getTicks(); //Clock_getTicks will return counts in 10us.
            return;
         } else {
            if (PIN_getInputValue(keyButton1) == true){
                button_released_time=Clock_getTicks(); //Clock_getTicks will return counts in 10us.
            }
        }
        if ( (button_released_time-button_pressed_time)>300000 )
            keysPressed |= KEY_RIGHT_HOLD_3SEC;
        else if ( (button_released_time-button_pressed_time)>0 )
            keysPressed |= KEY_RIGHT;

    }

    if(Timer_isActive(&keyChangeClock) != true)
    {
        Timer_start(&keyChangeClock);
    }
}

3. Define KEY_RIGHT_HOLD_3SEC in board_key.h

/*! Select Key ID */
#define KEY_SELECT            0x01
/*! Up Key ID */
#define KEY_UP                0x02
/*! Down Key ID */
#define KEY_DOWN              0x04
/*! Left Key ID */
#define KEY_LEFT              0x08
/*! Right Key ID */
#define KEY_RIGHT             0x10
/*! Hold 3 seconds Right Key ID */
#define KEY_RIGHT_HOLD_3SEC   0x20


4. Add "if(keysPressed == KEY_RIGHT_HOLD_3SEC){...}" in zclSampleSw_processKey of zcl_samplesw.c to process event for right button pressing and holding for 3 seconds.

static void zclSampleSw_processKey(uint8 keysPressed)
{
    //Button 1
    if(keysPressed == KEY_LEFT)
    {
        zstack_bdbStartCommissioningReq_t zstack_bdbStartCommissioningReq;

        if(ZG_BUILD_COORDINATOR_TYPE && ZG_DEVICE_COORDINATOR_TYPE)
        {
            zstack_bdbStartCommissioningReq.commissioning_mode = BDB_COMMISSIONING_MODE_NWK_FORMATION | BDB_COMMISSIONING_MODE_NWK_STEERING | BDB_COMMISSIONING_MODE_FINDING_BINDING;
            Zstackapi_bdbStartCommissioningReq(zclSampleSw_Entity,&zstack_bdbStartCommissioningReq);
        }
        else if (ZG_BUILD_JOINING_TYPE && ZG_DEVICE_JOINING_TYPE)
        {
            zstack_bdbStartCommissioningReq.commissioning_mode = BDB_COMMISSIONING_MODE_NWK_STEERING | BDB_COMMISSIONING_MODE_FINDING_BINDING;
            Zstackapi_bdbStartCommissioningReq(zclSampleSw_Entity,&zstack_bdbStartCommissioningReq);
        }
    }
    //Button 2
    if(keysPressed == KEY_RIGHT)
    {
        zstack_bdbGetZCLFrameCounterRsp_t Rsp;

        Zstackapi_bdbGetZCLFrameCounterReq(zclSampleSw_Entity, &Rsp);
        zclGeneral_SendOnOff_CmdToggle( SAMPLESW_ENDPOINT, &zclSampleSw_DstAddr, FALSE, Rsp.zclFrameCounter );
    }
    if(keysPressed == KEY_RIGHT_HOLD_3SEC)
    {
        //Event for right button pressing and holding for 3 seconds.
    }


}

Wednesday, October 31, 2018

How to use CC2531EMK and Wireshark as Zigbee sniffer.

The following steps show you how to use CC2531EMK and Wireshark as Zigbee sniffer.

1. Download and install TI Wireshark Packet Converter 1.

2. Download and install TI Packet sniffer to get sniffer_fw_cc2531.hex under C:\Program Files (x86)\Texas Instruments\SmartRF Tools\Packet Sniffer\bin\general\firmware. After getting sniffer_fw_cc2531.hex, you can download it to your CC2531EMK using CC Debugger.

3. Plug CC2531EMK into PC and start TiWsPc to select CC2531EMK and Zigbee channel to start TI Wireshark Packet Converter 1.



4. Download and install TI Packet sniffer 2. Copy ti802154ge-x64-2x.dll and tirpi-x64-2x.dll from C:\Program Files (x86)\Texas Instruments\SmartRF Tools\SmartRF Packet Sniffer 2\wireshark\plugins\2.4.x to C:\Program Files (x86)\Wireshark\plugins\2.4.8 (my Wireshar version is 2.4.8 and yours might be different.)

5. Open Wireshark go to Edit > Preferences > Protocols > Zigbee add the Zigbee TC Link Key 5a6967426565416c6c69616e63653039

6. Create a new Desktop shortcut for Wireshark and add the following to the path: -i\\.\pipe\tiwspc_data -k



7. Start Wireshark with the new shortcut created in step 6 and you will see Wireshark sniffing Zigbee data.


Tuesday, October 16, 2018

How to build TI Z-Stack Linux Home Gateway for Beaglebone Black


The following steps show you how to build TI Z-Stack Linux Home Gateway from source codes for Beaglebone Black.

1.Setup and run Ubuntu 18.04.01 on VirtualBox

2. Install build-essential with the following command

    sudo apt-get install build-essential

3. Change to home directory (mine is /home/yk) and install cross compiler for building BBB binary.
    
    wget -c https://releases.linaro.org/components/toolchain/binaries/6.4-2018.05/arm-linux-gnueabihf/gcc-linaro-6.4.1-2018.05-x86_64_arm-linux-gnueabihf.tar.xz
    
    tar xf gcc-linaro-6.4.1-2018.05-x86_64_arm-linux-gnueabihf.tar.xz

4. Add cross compiler path into PATH variable

     export PATH=$PATH:/home/yk/gcc-linaro-6.4.1-2018.05-x86_64_arm-linux-gnueabihf/bin

5. Add TCLIB path by the following command

     export TCLIB=/home/yk/gcc-linaro-6.4.1-2018.05-x86_64_arm-linux-gnueabihf/lib

6. Download Z-STACK-LINUX-GATEWAY and install to home directory (mine is ~/Z-Stack_Linux_Gateway-1.0.1-src).

7. Change directory to ~/Z-Stack_Linux_Gateway-1.0.1-src/Source and run "./build_all"

8. Will see the following error after build finished and it doesn't matter. You can find z-stack_linux_gateway_arm_binaries_.tar under /home/yk/Z-Stack_Linux_Gateway-1.0.1-src/Source/ERROR__out and you can scp z-stack_linux_gateway_arm_binaries_.tar to BBB to run/test it.




Thursday, October 11, 2018

How to use serial bootloader mode to download binary to LAUNCHXL-CC1310/LAUNCHXL-CC2650 using Flash Programmer 2

The following steps show you how to use serial bootloader mode to download binary to LAUNCHXL-CC1310/LAUNCHXL-CC2650 using Flash Programmer 2.

1. Select XDS110 CC1310 connection to do mass erase.


2. Select CC1310 and connect it to XDS110 Class Application/User Uart.




3. Select binary to download and you should see "Sucess!" after download.


Sunday, July 29, 2018

660 Zigbee devices in the same Zigbee network!


660 Zigbee devices in the same Zigbee network now!!! This time, we have total 660 Zigbee devices, including 130 ZRs (Smart Plugs) and 530 ZEDs (PIR motion sensors, Door Contact sensors, and Smoke Detectors), joined to a single Zigbee network. The solution is based on TI CC2530.




Tuesday, April 24, 2018

How to setup Mosquitto on Raspberry Pi and make Contiki/Contiki-NG cc26xx-web-demo do mqtt publish to it.

The following steps show you how to setup Mosquitto on Raspberry Pi and make Contiki/Contiki-NG cc26xx-web-demo do mqtt publish to it.

1. Login to Raspberry Pi and do the following steps to install Mosquitto.
  • 1.1 Run "apt-get update" and "apt-get install mosquitto" to install Mosquitto server.
  • 2.2 Run "apt-get install mosquitto-clients" to install mosquitto_sub and mosquitto_pub.
2. Follow steps in How to configure 6lbr to make it can do ping6 to a CC26xx/CC13xx node from Raspberry Pi running 6lbr to setup 6lbr in bridge router mode.

3. Do "ifconfig" to get br0 IPv6 address. In my case, it's "bbbb::e786:9d85:9446:709".


4. Go to cc26xx-web-demo MQTT/IBM Cloud Config page and set "bbbb::e786:9d85:9446:709" as broker IP.


5. Open another ssh login to Raspberry pi and run "mosquitto_sub -h bbbb::e786:9d85:9446:709 -t iot-2/evt/status/fmt/json" to subscribe to ccx6xx-web-demo publish topic. You should be it receives cc26xx-web-demo published MQTT messages.


p.s. You can also use "mosquitto_pub -h bbbb::e786:9d85:9446:709 -p 1883 -t iot-2/evt/status/fmt/json -m "hello"" to test MQTT message publish from Raspberry Pi terminal.

6. The following steps show you how to toggle red led on LAUNCHXL-CC1310 or LAUNCHXL-CC2560 running cc26xx-web-demo.
  •  Use "test" as Org ID instead of "quickstart" and "123456" as Auth Token instead of empty.
  • Click "Submit" to make cc26xx-web-demo to reconnect to mqtt server.
  • Start a ssh login to raspberry pi. Use "mosquitto_pub -h bbbb::e786:9d85:9446:709 -m "1" -t iot-2/cmd/leds/fmt/json" to turn on red led, or "mosquitto_pub -h bbbb::e786:9d85:9446:709 -m "0" -t iot-2/cmd/leds/fmt/json" to turn off red led.