Skip to content

Commit

Permalink
[Ameba] Support BLE & IP commissioning functions (#10841)
Browse files Browse the repository at this point in the history
* Support commissioning over BLE

* Revise files

* Update files to match B1021

* Fix restyled errors

* Remove outdated comments

* Update README.md and wordlist

* Rename mDNS abstract layer to DNS-SD for Ameba

* Minor fixes on the typos

* Update for the review questions
  • Loading branch information
pankore authored and andreilitvin committed Nov 3, 2021
1 parent 2fb9f49 commit 8b990bb
Show file tree
Hide file tree
Showing 38 changed files with 3,340 additions and 138 deletions.
5 changes: 4 additions & 1 deletion .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ attrMask
attSizeBytes
attType
ATW
ATWC
AudioOutput
auth
autoconnect
Expand Down Expand Up @@ -138,13 +139,15 @@ CHIPCryptoPALHsm
CHIPDeviceController
ChipDeviceCtrl
CHIPDeviceEvent
CHIPDevicePlatformConfig
CHIPDevicePlatformEvent
ChipEchoRequester
ChipEchoResponder
ChipImInitiator
ChipImResponder
ChipLight
ChipMessageLayer
CHIPOBLE
CHIPTest
CHIPTool
chmod
Expand Down Expand Up @@ -797,9 +800,9 @@ ScriptBinding
SDC
SDHC
SDK
SDK's
sdkconfig
SDKs
SDK's
SDKTARGETSYSROOT
sdl
segger
Expand Down
8 changes: 5 additions & 3 deletions config/ameba/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ chip_ble_project_config_include = ""
mbedtls_target = "//mbedtls:mbedtls"
lwip_platform = "external"

chip_build_tests = true
chip_build_tests = false

chip_inet_config_enable_tcp_endpoint = true
chip_inet_config_enable_udp_endpoint = true

chip_bypass_rendezvous = true
chip_config_network_layer_ble = false
chip_bypass_rendezvous = false
chip_config_network_layer_ble = true
chip_ip_commissioning = true
chip_use_clusters_for_ip_commissioning = true

custom_toolchain = "//third_party/connectedhomeip/config/ameba/toolchain:ameba"
4 changes: 2 additions & 2 deletions config/ameba/chip.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ list(
-DCONFIG_FUNCION_O0_OPTIMIZE
-DDM_ODM_SUPPORT_TYPE=32
-DCHIP_DEVICE_LAYER_TARGET=Ameba
-DMBEDTLS_CONFIG_FILE=\\\"mbedtls_config.h\\\"
-DMBEDTLS_CONFIG_FILE=<mbedtls_config.h>
-D_POSIX_REALTIME_SIGNALS
)

list(
Expand Down Expand Up @@ -96,7 +97,6 @@ string(APPEND CHIP_GN_ARGS "ameba_ar = \"arm-none-eabi-ar\"\n")
string(APPEND CHIP_GN_ARGS "ameba_cc = \"arm-none-eabi-gcc\"\n")
string(APPEND CHIP_GN_ARGS "ameba_cxx = \"arm-none-eabi-c++\"\n")
string(APPEND CHIP_GN_ARGS "ameba_cpu = \"ameba\"\n")
string(APPEND CHIP_GN_ARGS "chip_build_tests = false\n")

file(GENERATE OUTPUT ${CHIP_OUTPUT}/args.gn CONTENT ${CHIP_GN_ARGS})

Expand Down
Empty file modified examples/all-clusters-app/ameba/.gitignore
100644 → 100755
Empty file.
104 changes: 85 additions & 19 deletions examples/all-clusters-app/ameba/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ control.
- [Building the Example Application](#building-the-example-application)
- [Commissioning and cluster control](#commissioning-and-cluster-control)
- [Commissioning](#commissioning)
- [Bypass mode](#bypass-mode)
- [BLE mode](#ble-mode)
- [IP mode](#ip-mode)
- [Cluster control](#cluster-control)

---
Expand Down Expand Up @@ -40,36 +43,99 @@ The CHIP demo application is supported on
The output image files are stored in
`out/ameba-amebad-all-clusters/asdk/image` folder.

The bootloader image files are stored in
`out/ameba-amebad-all-clusters/asdk/bootloader` folder.

- After building the application, **Ameba Image Tool** is used to flash it to
Ameba board.

1. Connect your device via USB and open Ameba Image Tool.
2. Select correct serial port and set baudrate as **115200**.
3. Browse and add the corresponding image files in the Flash Download list to
the correct locations
4. Click **Download** button.
1. Connect your device via USB and open Ameba Image Tool.
2. Select correct serial port and set baudrate as **115200**.
3. Browse and add the corresponding image files in the Flash Download list to
the correct locations
4. Click **Download** button.

## Commissioning and Cluster Control

### Commissioning
## Commissioning

There are three commissioning modes supported by Ameba platform:

### Bypass mode

1. In "connectedhomeip/config/ameba/args.gni"

- set `chip_bypass_rendezvous = true`
- Set `chip_ip_commissioning = false`
- Set `chip_use_clusters_for_ip_commissioning = false`
- Set `chip_config_network_layer_ble = false`

2. In "connectedhomeip/src/platform/Ameba/CHIPDevicePlatformConfig.h"

- Set `#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 0`

3. Build and Flash
4. Use ATS\$ command to run all-cluster example.
5. Connect to AP using `ATW0, ATW1, ATWC` commands
6. Test with
[Chip-Tool](https://github.com/project-chip/connectedhomeip/tree/master/examples/chip-tool)
or
[Python Controller](https://github.com/project-chip/connectedhomeip/blob/master/docs/guides/python_chip_controller_building.md).

### BLE mode

1. In "connectedhomeip/config/ameba/args.gni"

The commissioning is carried out via WiFi.
- set `chip_bypass_rendezvous = false`
- Set `chip_ip_commissioning = false`
- Set `chip_use_clusters_for_ip_commissioning = false`
- Set `chip_config_network_layer_ble = true`

1. After download all-cluster example to Ameba board, boot up the board by
pressing the reset button.
2. Use ATW commands to setup network.
3. Use ATS\$ command to run all-cluster example.
4. Use
[standalone chip-tool](https://github.com/project-chip/connectedhomeip/tree/master/examples/chip-tool)
to communicate with the device.
2. In "connectedhomeip/src/platform/Ameba/CHIPDevicePlatformConfig.h"

$ ./chip-tool pairing bypass ${NODE_ID_TO_ASSIGN} 192.168.xx.xxx 5540
- Set `#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1`

### Cluster Control
3. Build and Flash
4. Use ATS\$ command to run all-cluster example.
5. Test with
[Chip-Tool](https://github.com/project-chip/connectedhomeip/tree/master/examples/chip-tool)
or
[Python Controller](https://github.com/project-chip/connectedhomeip/blob/master/docs/guides/python_chip_controller_building.md).

- After successful commissioning, use the OnOff cluster command to control the
OnOff attribute. This allows you to toggle a parameter implemented by the
device to be On or Off.
### IP mode

1. In "connectedhomeip/config/ameba/args.gni"

- set `chip_bypass_rendezvous = false`
- Set `chip_ip_commissioning = true`
- Set `chip_use_clusters_for_ip_commissioning = true`
- Set `chip_config_network_layer_ble = false`

2. In "connectedhomeip/src/platform/Ameba/CHIPDevicePlatformConfig.h"

- Set `#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 0`

3. Build and Flash
4. Use ATS\$ command to run all-cluster example.
5. Connect to AP using `ATW0, ATW1, ATWC` commands
6. Test with
[Chip-Tool](https://github.com/project-chip/connectedhomeip/tree/master/examples/chip-tool)
or
[Python Controller](https://github.com/project-chip/connectedhomeip/blob/master/docs/guides/python_chip_controller_building.md).

## Cluster Control

After successful commissioning, use the OnOff cluster command to control the
OnOff attribute. This allows you to toggle a parameter implemented by the device
to be On or Off.

- Via
[Chip-Tool](https://github.com/project-chip/connectedhomeip/tree/master/examples/chip-tool#using-the-client-to-send-matter-commands)

$ ./chip-tool onoff on 1
$ ./chip-tool onoff off 1

- Via
[Python Controller](https://github.com/project-chip/connectedhomeip/blob/master/docs/guides/python_chip_controller_building.md#step-8-control-application-zcl-clusters)

$ chip-device-ctrl > zcl OnOff Toggle 1234 1 0
3 changes: 3 additions & 0 deletions examples/all-clusters-app/ameba/chip_main.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ list(
${chip_dir}/examples/all-clusters-app/ameba/main/chipinterface.cpp
${chip_dir}/examples/all-clusters-app/ameba/main/DeviceCallbacks.cpp
${chip_dir}/examples/all-clusters-app/ameba/main/CHIPDeviceManager.cpp
${chip_dir}/examples/all-clusters-app/ameba/main/Globals.cpp
${chip_dir}/examples/all-clusters-app/ameba/main/LEDWidget.cpp
)

add_library(
Expand Down Expand Up @@ -81,6 +83,7 @@ list(
-DCHIP_DEVICE_LAYER_TARGET=Ameba
-DUSE_ZAP_CONFIG
-DCHIP_HAVE_CONFIG_H
-DMBEDTLS_CONFIG_FILE=<mbedtls_config.h>
)

list(
Expand Down
5 changes: 5 additions & 0 deletions examples/all-clusters-app/ameba/main/CHIPDeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ CHIP_ERROR CHIPDeviceManager::Init(CHIPDeviceManagerCallbacks * cb)
err = PlatformMgr().InitChipStack();
SuccessOrExit(err);

if (CONFIG_NETWORK_LAYER_BLE)
{
ConnectivityMgr().SetBLEAdvertisingEnabled(true);
}

err = Platform::MemoryInit();
SuccessOrExit(err);

Expand Down
79 changes: 72 additions & 7 deletions examples/all-clusters-app/ameba/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
#include <support/logging/CHIPLogging.h>
#include <support/logging/Constants.h>

#include "Globals.h"
#include "LEDWidget.h"

static const char * TAG = "app-devicecallbacks";

using namespace ::chip;
Expand All @@ -51,29 +54,91 @@ constexpr uint32_t kIdentifyTimerDelayMS = 250;

void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_t arg)
{
// TODO
// Add callback functions for different ChipDeviceEvent Types
switch (event->Type)
{
case DeviceEventType::kInternetConnectivityChange:
OnInternetConnectivityChange(event);
break;

case DeviceEventType::kSessionEstablished:
OnSessionEstablished(event);
break;
case DeviceEventType::kInterfaceIpAddressChanged:
if ((event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV4_Assigned) ||
(event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned))
{
// MDNS server restart on any ip assignment: if link local ipv6 is configured, that
// will not trigger a 'internet connectivity change' as there is no internet
// connectivity. MDNS still wants to refresh its listening interfaces to include the
// newly selected address.
chip::app::DnssdServer::Instance().StartServer();
}
break;
}
}

void DeviceCallbacks::PostAttributeChangeCallback(EndpointId endpointId, ClusterId clusterId, AttributeId attributeId, uint8_t mask,
uint8_t type, uint16_t size, uint8_t * value)
{
ChipLogProgress(DeviceLayer,
"[%s] PostAttributeChangeCallback - Cluster ID: 0x%04x, EndPoint ID: 0x%02x, Attribute ID: 0x%04x\r\n", TAG,
clusterId, endpointId, attributeId);

switch (clusterId)
{
case ZCL_ON_OFF_CLUSTER_ID:
OnOnOffPostAttributeChangeCallback(endpointId, attributeId, value);
break;

case ZCL_IDENTIFY_CLUSTER_ID:
OnIdentifyPostAttributeChangeCallback(endpointId, attributeId, value);
break;

default:
ChipLogProgress(DeviceLayer, "[%s] Unhandled cluster ID: 0x%04x\r\n", TAG, clusterId);
break;
}
}

void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event)
{
if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established)
{
ChipLogProgress(DeviceLayer, "Server ready at: %s:%d", event->InternetConnectivityChange.address, CHIP_PORT);
chip::app::DnssdServer::Instance().StartServer();
}
else if (event->InternetConnectivityChange.IPv4 == kConnectivity_Lost)
{
ChipLogProgress(DeviceLayer, "Lost IPv4 connectivity...");
}
if (event->InternetConnectivityChange.IPv6 == kConnectivity_Established)
{
ChipLogProgress(DeviceLayer, "IPv6 Server ready...");
chip::app::DnssdServer::Instance().StartServer();
}
else if (event->InternetConnectivityChange.IPv6 == kConnectivity_Lost)
{
ChipLogProgress(DeviceLayer, "Lost IPv6 connectivity...");
}
}

void DeviceCallbacks::OnSessionEstablished(const ChipDeviceEvent * event)
{
if (event->SessionEstablished.IsCommissioner)
{
ChipLogProgress(DeviceLayer, "Commissioner detected!");
}
}

void DeviceCallbacks::OnOnOffPostAttributeChangeCallback(EndpointId endpointId, AttributeId attributeId, uint8_t * value)
{
VerifyOrExit(attributeId == ZCL_ON_OFF_ATTRIBUTE_ID,
ChipLogError(DeviceLayer, TAG, "Unhandled Attribute ID: '0x%04x", attributeId));
VerifyOrExit(endpointId == 1 || endpointId == 2,
ChipLogError(DeviceLayer, TAG, "Unexpected EndPoint ID: `0x%02x'", endpointId));

// At this point we can assume that value points to a bool value.
statusLED1.Set(*value);

exit:
return;
}

void IdentifyTimerHandler(Layer * systemLayer, void * appState, CHIP_ERROR error)
{
if (identifyTimerCount)
Expand Down
21 changes: 21 additions & 0 deletions examples/all-clusters-app/ameba/main/Globals.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
*
* Copyright (c) 2020 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "Globals.h"

LEDWidget statusLED1;
Loading

0 comments on commit 8b990bb

Please sign in to comment.