Skip to content

Using CHIP Lighting app example on Linux

Lukasz Gniadzik edited this page Apr 6, 2021 · 1 revision

Developers who have just started to work with the CHIP project may be a little bit confused with multiple available examples ported to multiple platform.
The good start point here may be selecting example which represents actual ZCL cluster device:

  • lighting app
  • lock app

Both of them emulate devices which control bulb lighting level or door bolt lock state - everything under CHIP protocol control.
Someone may notice that only 'lighting app' has been ported to linux platform and there is no 'lock app' there.
That's true but still, the 'lighting app' example may be used to test receiving DoorLock and Lighting ZCL commands simultaneously what gives a great reference for the CHIP protocol analysis.

Building 'Lighting app' example

The 'Lighting app' example can be build in two ways:

  • inside chip-vscode container
  • directly on the host system (>= Ubuntu 20.4)

Detailed instruction can be found here: https://github.com/ARMmbed/connectedhomeip/tree/development/examples/lighting-app/linux

  • Install tool chain

      $ sudo apt-get install git gcc g++ python pkg-config libssl-dev libdbus-1-dev libglib2.0-dev ninja-build python3-venv python3-dev unzip
    
  • Build the example application:

      $ cd ~/connectedhomeip/examples/lighting-app/linux
      $ git submodule update --init
      $ source third_party/connectedhomeip/scripts/activate.sh
      $ gn gen out/debug --args='chip_bypass_rendezvous=true'
      $ ninja -C out/debug
    
  • To delete generated executable, libraries and object files use:

      $ cd ~/connectedhomeip/examples/lighting-app/linux
      $ rm -rf out/
    

Running example on Linux host or Raspberry Pi 4 (tested on Ubunbtu Server 20.04)

Simply run:

$./chip-tool-server --wifi

Above command will run CHIP server on the device and start listening on port 11097.

Testing communication with the device

The chip-tool (CHIP client) application can be used to test communication with the device,. Depending on scenario there are two options here:

  • using Android CHIPTool application -> 'LIGHT ON/OFF & LEVEL CLUSTER' button
  • using linux chip-tool example

NOTE 1: .apk files for Android CHIPTool app can be found here: https://github.com/ARMmbed/connectedhomeip/actions/runs/722209395

NOTE 2: Instruction for building linux chip-tool example can be found here: https://github.com/ARMmbed/connectedhomeip/blob/development/examples/chip-tool/README.md


To communicate with the device using linux chip-tool application, client has to send pairing request to the device.
The command below pair a client with the provided IP address and port of the server to talk to:

$ ./chip-tool pairing bypass 192.168.0.30 11097

NOTE: Please remember that we configured server to bypass Rendezvous

Finally to use the Client to send a CHIP commands, run chip-tool executable once again and pass it the target cluster name, the target command name as well as an endpoint id:

$ ./chip-tool onoff on 1

Above command will result in below response on the server side:

...
CHIP:SVR: Packet received from UDP:192.168.8.181:11098: 14 bytes
CHIP:ZCL: APS frame processing success!
CHIP:ZCL: RX len 3, ep 1, clus 0x 6 
CHIP:ZCL:  FC 1 seq 0 cmd 1 payload[
CHIP:ZCL: NULL
CHIP:ZCL: ]
CHIP:ZCL: On/Off set value: 1 1
CHIP:ZCL: Toggle on/off from 0 to 1
LightingManager::InitiateAction(ON_ACTION)CHIP:ZCL: Unknown cluster ID: 8
CHIP:ZCL: Measured APS frame size 11
CHIP:ZCL: Successfully encoded 11 bytes
CHIP:IN: Secure message was encrypted: Msg ID 2
CHIP:IN: Sending msg from 12344321 to 112233
CHIP:IN: Sending secure msg on generic transport
CHIP:IN: Secure msg send status 0
CHIP:ZCL: T   0:TX (0xaaaada193c10) Ucast 0x00xaaaada193c08
CHIP:ZCL: TX buffer: [
CHIP:ZCL: 08 00 0B 01 00 
CHIP:ZCL: ]
CHIP:ZCL: Data model processing success!
...