Wednesday, August 26, 2015

How to create a periodic event in TI Z-Stack or BLE-Stack

The following codes are example to start PERIODIC_EVT every second and you can do any periodic processing in PERIODIC_EVT.

//Put where you want to start PERIODIC_EVT
osal_start_timerEx( XXX_TaskID, SENSOR_READ_EVT, 1000 );

//For Z-Stack, create PERIODIC_EVT processing in zcl_XXX_event_loop
//For BLE-Stack, create PERIODIC_EVT processing in xxx_ProcessEvent
  if( events & PERIODIC_EVT )
  {
    //Do things that need periodic processing here!
    ...
    osal_start_timerEx( XXX_TaskID, PERIODIC_EVT, 1000 );
    return (events ^ PERIODIC_EVT);
  }

Friday, August 21, 2015

How to build Contiki 6lbr Slip Radio on CC2538EM with USB Drivers

1. Git the latest Contiki code by running "git clone --recursive https://github.com/contiki-os/contiki"
2. Open Makefile under examples/ipv6/slip-radio/ and set SMALL=0
3. Open contiki-conf.h under platform/cc2538dk/ and make the following changes:
     #define UART_CONF_ENABLE            0
     #define SLIP_ARCH_CONF_USB         1
     #define DBG_CONF_USB                     1
     #define CC2538_RF_CONF_CHANNEL              25
     #define IEEE802154_CONF_PANID                    0xABCD
4. Build the Slip-Radio (examples/ipv6/slip-radio/) with “make TARGET=cc2538dk”
5. Program slip-radio.bin to the CC2538EM with SmartRF06 board and Flash Programmer.

Monday, August 17, 2015

Setup 6lbr to run 6LowPAN with CC2531 USB dongle on Raspberry Pi 2B

1. Unzip and flash a CC2531 USB dongle with cc2531-slip-radio_contikimac.zip.
2. SSH login to Raspberry Pi.
3. sudo apt-get install libncurses5-dev
4. sudo apt-get install bridge-utils
5. sudo vi /boot/cmdline.txt file and add the following configuration parameter in the beginning of cmdline.txt
    dwc_otg.speed=1
6a. git clone --recursive https://github.com/cetic/6lbr
6b. cd 6lbr and run "sudo git submodule sync" and "sudo git submodule update --init"
7. cd 6lbr/examples/6lbr
8. make all plugins tools ---> This step takes lots of time so go for a break!
9. sudo make install
10. Create /etc/6lbr/6lbr.conf with the content below
      MODE=ROUTER

      RAW_ETH=1
      BRIDGE=0
      DEV_BRIDGE=br0
      DEV_TAP=tap0
      DEV_ETH=eth0
      RAW_ETH_FCS=0

      DEV_RADIO=/dev/ttyACM0
      BAUDRATE=115200

      LOG_LEVEL=3
11. Change to channel 25,which is used by cc26xx Contiki port
      $sudo /usr/lib/6lbr/bin/nvm_tool --update --channel 25 /etc/6lbr/nvm.dat
12. Run "/usr/lib/6lbr/bin/nvm_tool --print /etc/6lbr/nvm.dat" to make sure it switches to channel 25.

13. Plug CC2531 USB dongle to Raspberry Pi and the dongle should appear as /dev/ttyACM0. Run "sudo lsusb -v" to verify this.

14. run "sudo service 6lbr start" to start 6lbr.

15. Open browser like Firefox and input [bbbb::100].


How to setup Contiki Sniffer for 6LowPAN using CC2531 USB dongle or CC2538EM

The following steps show you how to setup Contiki Sniffer on Mac OS for 6LowPAN using CC2531 USB dongle in details.

1. Download pyserial-2.7.tar.gz and untar it by running "tar zxvf pyserial-2.7.tar.gz" under console terminal of Mac OS.

2. Install pySerial by running "sudo python setup.py install" under console terminal of Mac OS.

3. Download sensniff.py.

4. Download Contiki_Sniffer_CC2531EMK.hex to CC2531 USB dongle using TI CC Debugger and Flash Programmer.

p.s. If you want to use CC2538EM as sniffer, you have to set "#define CC2538_RF_CONF_SNIFFER_USB  1" in C:\contiki\platform\cc2538dk\contiki-conf.h and do make under "C:\contiki\examples\cc2538dk\sniffer". You will get sniffer.bin under "C:\contiki\examples\cc2538dk\sniffer" and flash is to CC2538EM using Flash Programmer 2.

5. Plugin CC2351 USB dongle or CC2538EM into Mac USB port and you should see it enum like /dev/tty.usbmodem1421. Please note that 1421 might be different from device to device.

6. Run "python sensniff.py -d /dev/tty.usbmodem1421 -b 460800" under console terminal of Mac OS.

p.s. CC2531 USB dongle needs you to press S1 or S2 button to make it work after you plug it into UAB port. I don't know why but if you cannot make it work, try it.

7. Download and install wireshark.

8. Run wireshark. Go to Edit->Preferences->Protocols->6LowPAN and add "aaaa::" to Context 0:.

9. Go to Edit->Preferences->Protocols->IEEE802.15.4 and check "TI CC24xx FCS format".

10. Go to Capture -> options -> Manage Interfaces -> New. Input /tmp/sensniff to "Pipe:" and save.

11. Start a new live capture on wireshark and enjoy it.