Skip to content

Commit

Permalink
Added ota-requestor for lighting app and updated readme. (project-chi…
Browse files Browse the repository at this point in the history
…p#13532)

Removed applyupdate command from ota-requestor-app as
ota-announce automatically apply the updates once trasnfer completes.
Minor readme changes.
  • Loading branch information
jadhavrohit924 authored and selissia committed Jan 28, 2022
1 parent e8b2b8b commit 9dcf66b
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 68 deletions.
4 changes: 2 additions & 2 deletions examples/all-clusters-app/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ remote device, as well as the network credentials to use.
The command below uses the default values hard-coded into the debug versions of
the ESP32 all-clusters-app to commission it onto a Wi-Fi network:

$ .out/debug/chip-tool pairing ble-wifi 12344321 ${SSID} ${PASSWORD} 20202021 3840
$ ./out/debug/chip-tool pairing ble-wifi 12344321 ${SSID} ${PASSWORD} 20202021 3840

Parameters:

Expand All @@ -210,7 +210,7 @@ Parameters:
To use the Client to send Matter commands, run the built executable and pass it
the target cluster name, the target command name as well as an endpoint id.

$ .out/debug/chip-tool onoff on 12344321 1
$ ./out/debug/chip-tool onoff on 12344321 1

The client will send a single command packet and then exit.

Expand Down
4 changes: 2 additions & 2 deletions examples/bridge-app/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ remote device, as well as the network credentials to use.
The command below uses the default values hard-coded into the debug versions of
the ESP32 all-clusters-app to commission it onto a Wi-Fi network:

$ .out/debug/chip-tool pairing ble-wifi 12344321 ${SSID} ${PASSWORD} 20202021 3840
$ ./out/debug/chip-tool pairing ble-wifi 12344321 ${SSID} ${PASSWORD} 20202021 3840

Parameters:

Expand All @@ -242,6 +242,6 @@ Parameters:
To use the Client to send Matter commands, run the built executable and pass it
the target cluster name, the target command name as well as an endpoint id.

$ .out/debug/chip-tool onoff on 12344321 1
$ ./out/debug/chip-tool onoff on 12344321 2

The client will send a single command packet and then exit.
39 changes: 39 additions & 0 deletions examples/lighting-app/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This example demonstrates the Matter Lighting application on ESP platforms.
- [Building the Example Application](#building-the-example-application)
- [Commissioning over BLE using chip-tool](#commissioning-over-ble-using-chip-tool)
- [Cluster Control](#cluster-control)
- [Steps to Try Lighting app OTA Requestor](#steps-to-try-lighting-app-ota-requestor)

---

Expand Down Expand Up @@ -122,3 +123,41 @@ make sure the IDF_PATH has been exported(See the manual setup steps above).
control the color attributes:

$ ./out/debug/chip-tool colorcontrol move-to-hue-and-saturation 240 100 0 0 0 12345 1

# Steps to Try Lighting app OTA Requestor

Before moving ahead, make sure your device is commissioned and running.

- Build the Linux OTA Provider

```
scripts/examples/gn_build_example.sh examples/ota-provider-app/linux out/debug chip_config_network_layer_ble=false
```

- Run the Linux OTA Provider with OTA image.

```
./out/debug/chip-ota-provider-app -f hello-world.bin
```

hello-world.bin can be obtained from compiling the hello-world ESP-IDF example.

- Provision the Linux OTA Provider using chip-tool

```
./out/debug/chip-tool pairing onnetwork 12345 20202021
```

## Query for an OTA Image

After commissioning is successful, press Enter in requestor device console and
type below query.

```
>matter ota query 1 12345 0
```

## Apply update

Once transfer is complete, reboot the device manually to boot from upgraded OTA
image.
3 changes: 2 additions & 1 deletion examples/lighting-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ idf_component_register(PRIV_INCLUDE_DIRS
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/thread-network-diagnostics-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/user-label-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/wifi-network-diagnostics-server"
PRIV_REQUIRES chip QRCode bt led_strip)
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ota-requestor"
PRIV_REQUIRES chip QRCode bt led_strip app_update)

set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17)
target_compile_options(${COMPONENT_LIB} PRIVATE "-DLWIP_IPV6_SCOPES=0" "-DCHIP_HAVE_CONFIG_H")
26 changes: 26 additions & 0 deletions examples/lighting-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,46 @@
#include "freertos/task.h"
#include "nvs_flash.h"
#include "shell_extension/launch.h"
#include <app/clusters/ota-requestor/BDXDownloader.h>
#include <app/clusters/ota-requestor/OTARequestor.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <platform/ESP32/OTAImageProcessorImpl.h>
#include <platform/GenericOTARequestorDriver.h>

using namespace ::chip;
using namespace ::chip::Credentials;
using namespace ::chip::DeviceManager;
using namespace ::chip::DeviceLayer;

#if CONFIG_ENABLE_OTA_REQUESTOR
OTARequestor gRequestorCore;
GenericOTARequestorDriver gRequestorUser;
BDXDownloader gDownloader;
OTAImageProcessorImpl gImageProcessor;
#endif

LEDWidget AppLED;

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

static DeviceCallbacks EchoCallbacks;

static void InitOTARequestor(void)
{
#if CONFIG_ENABLE_OTA_REQUESTOR
SetRequestorInstance(&gRequestorCore);
gRequestorCore.SetServerInstance(&Server::GetInstance());
gRequestorCore.SetOtaRequestorDriver(&gRequestorUser);
gImageProcessor.SetOTADownloader(&gDownloader);
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
gRequestorUser.Init(&gRequestorCore, &gImageProcessor);
gRequestorCore.SetBDXDownloader(&gDownloader);
#endif
}

static void InitServer(intptr_t context)
{
// Print QR Code URL
Expand Down Expand Up @@ -82,5 +106,7 @@ extern "C" void app_main()

AppLED.Init();

InitOTARequestor();

chip::DeviceLayer::PlatformMgr().ScheduleWork(InitServer, reinterpret_cast<intptr_t>(nullptr));
}
5 changes: 3 additions & 2 deletions examples/lighting-app/esp32/partitions.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Name, Type, SubType, Offset, Size, Flags
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
nvs, data, nvs, , 0x6000,
otadata, data, ota, , 0x2000,
phy_init, data, phy, , 0x1000,
# Factory partition size about 1.9MB
factory, app, factory, , 1945K,
ota_0, app, ota_0, , 1500K,
ota_1, app, ota_1, , 1500K,
4 changes: 4 additions & 0 deletions examples/lighting-app/esp32/sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
#enable lwIP route hooks
CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y
CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y

# Serial Flasher config
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
4 changes: 2 additions & 2 deletions examples/lock-app/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ remote device, as well as the network credentials to use.
The command below uses the default values hard-coded into the debug versions of
the ESP32 all-clusters-app to commission it onto a Wi-Fi network:

$ .out/debug/chip-tool pairing ble-wifi 12344321 ${SSID} ${PASSWORD} 20202021 3840
$ ./out/debug/chip-tool pairing ble-wifi 12344321 ${SSID} ${PASSWORD} 20202021 3840

Parameters:

Expand All @@ -186,7 +186,7 @@ Parameters:
To use the Client to send Matter commands, run the built executable and pass it
the target cluster name, the target command name as well as an endpoint id.

$ .out/debug/chip-tool onoff on 12344321 1
$ ./out/debug/chip-tool onoff on 12344321 1

The client will send a single command packet and then exit.

Expand Down
15 changes: 4 additions & 11 deletions examples/ota-requestor-app/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,13 @@ After commissioning is successful, announce OTA provider's presence using
chip-tool. On receiving this command OTA requestor will query for OTA image.

```
./out/debug/chip-tool otasoftwareupdaterequestor announce-ota-provider 12345 0 0 12346 0
./out/debug/chip-tool otasoftwareupdaterequestor announce-ota-provider 12345 0 0 0 12346 0
```

## Apply update request
## Apply update

Once transfer is complete OTA Requestor should take permission from the OTA
Provider for applying the OTA image. Use the following command from OTA
requestor prompt

```
esp32> ApplyUpdateRequest
```

Then reboot the device manually to boot from upgraded OTA image.
Once transfer is complete, reboot the device manually to boot from upgraded OTA
image.

## ESP32 OTA Requestor with Linux OTA Provider

Expand Down
47 changes: 0 additions & 47 deletions examples/ota-requestor-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@
#include <app/clusters/ota-requestor/OTARequestor.h>
#include <app/server/Server.h>

#include <cmath>
#include <cstdio>
#include <string>
#include <vector>

#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>

Expand All @@ -45,64 +40,23 @@
#include "OTAImageProcessorImpl.h"
#include "platform/GenericOTARequestorDriver.h"
#include "platform/OTARequestorInterface.h"
#include <argtable3/argtable3.h>
#include <esp_console.h>

using namespace ::chip;
using namespace ::chip::System;
using namespace ::chip::Credentials;
using namespace ::chip::DeviceManager;
using namespace ::chip::DeviceLayer;

struct CmdArgs
{
struct arg_end * end;
};

namespace {
const char * TAG = "ota-requester-app";
static DeviceCallbacks EchoCallbacks;
CmdArgs applyUpdateCmdArgs;

OTARequestor gRequestorCore;
GenericOTARequestorDriver gRequestorUser;
BDXDownloader gDownloader;
OTAImageProcessorImpl gImageProcessor;
} // namespace

int ESPApplyUpdateCmdHandler(int argc, char ** argv)
{
gRequestorCore.ApplyUpdate();
ESP_LOGI(TAG, "Apply the Update");
return 0;
}

void ESPInitConsole(void)
{
esp_console_repl_t * repl = NULL;
esp_console_repl_config_t replConfig = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
esp_console_dev_uart_config_t uartConfig = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
/* Prompt to be printed before each line.
* This can be customized, made dynamic, etc.
*/
replConfig.prompt = "esp32 >";

esp_console_register_help_command();

esp_console_cmd_t applyUpdateCommand;
memset(&applyUpdateCommand, 0, sizeof(applyUpdateCommand));

applyUpdateCmdArgs.end = arg_end(1);

applyUpdateCommand.command = "ApplyUpdateRequest", applyUpdateCommand.help = "Request to OTA update image",
applyUpdateCommand.func = &ESPApplyUpdateCmdHandler, applyUpdateCommand.argtable = &applyUpdateCmdArgs;

esp_console_cmd_register(&applyUpdateCommand);

esp_console_new_repl_uart(&uartConfig, &replConfig, &repl);
esp_console_start_repl(repl);
}

extern "C" void app_main()
{
ESP_LOGI(TAG, "OTA Requester!");
Expand Down Expand Up @@ -140,7 +94,6 @@ extern "C" void app_main()
// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());

ESPInitConsole();
SetRequestorInstance(&gRequestorCore);
gRequestorCore.Init(&(Server::GetInstance()), &gRequestorUser, &gDownloader);
gImageProcessor.SetOTADownloader(&gDownloader);
Expand Down
2 changes: 1 addition & 1 deletion examples/temperature-measurement-app/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ remote device, as well as the network credentials to use.
The command below uses the default values hard-coded into the debug versions of
the ESP32 all-clusters-app to commission it onto a Wi-Fi network:

$ .out/debug/chip-tool pairing ble-wifi 12344321 ${SSID} ${PASSWORD} 20202021 3840
$ ./out/debug/chip-tool pairing ble-wifi 12344321 ${SSID} ${PASSWORD} 20202021 3840

Parameters:

Expand Down

0 comments on commit 9dcf66b

Please sign in to comment.