Skip to content

Commit 764fc6e

Browse files
kkasperczyk-noArekBalysNordic
authored andcommitted
samples: matter: Fixed deferred attribute persister
Fixed problems with not working deferred attribute persister due to missining initialization. Signed-off-by: Kamil Kasperczyk <[email protected]>
1 parent 73bfead commit 764fc6e

File tree

5 files changed

+42
-3
lines changed

5 files changed

+42
-3
lines changed

doc/nrf/releases_and_maturity/migration/migration_guide_3.1.rst

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,37 @@ Matter
3838

3939
* The :kconfig:option:`CONFIG_NCS_SAMPLE_MATTER_ZAP_FILE_PATH` Kconfig option has been introduced.
4040
Previously, the path to the ZAP file was deduced based on hardcoded locations.
41-
Now, the location is configured using :kconfig:option:`CONFIG_NCS_SAMPLE_MATTER_ZAP_FILE_PATH` Kconfig option.
42-
This change requires you to update your application ``prj.conf`` file by setting :kconfig:option:`CONFIG_NCS_SAMPLE_MATTER_ZAP_FILE_PATH` to point the location of you ZAP file.
41+
Now, the location is configured using the :kconfig:option:`CONFIG_NCS_SAMPLE_MATTER_ZAP_FILE_PATH` Kconfig option.
42+
This change requires you to update your application ``prj.conf`` file by setting the :kconfig:option:`CONFIG_NCS_SAMPLE_MATTER_ZAP_FILE_PATH` option to point the location of you ZAP file.
43+
44+
* For the :ref:`Matter light bulb <matter_light_bulb_sample>` sample:
45+
46+
* The deferred attribute persistence implementation has changed in the latest Matter version and you must align it as follows:
47+
48+
* Remove the following lines from the :file:`app_task.cpp` file located in the application's :file:`src` directory:
49+
50+
.. code-block:: C++
51+
52+
#include <app/DeferredAttributePersistenceProvider.h>
53+
54+
DeferredAttributePersistenceProvider gDeferredAttributePersister(Server::GetInstance().GetDefaultAttributePersister(),
55+
Span<DeferredAttribute>(&gCurrentLevelPersister, 1),
56+
System::Clock::Milliseconds32(5000));
57+
58+
* Add the following lines to the :file:`app_task.cpp` file located in the application's :file:`src` directory:
59+
60+
.. code-block:: C++
61+
62+
#include <app/util/persistence/DefaultAttributePersistenceProvider.h>
63+
#include <app/util/persistence/DeferredAttributePersistenceProvider.h>
64+
65+
DefaultAttributePersistenceProvider gSimpleAttributePersistence;
66+
DeferredAttributePersistenceProvider gDeferredAttributePersister(gSimpleAttributePersistence,
67+
Span<DeferredAttribute>(&gCurrentLevelPersister, 1),
68+
System::Clock::Milliseconds32(5000));
69+
70+
* Modify the ``mPostServerInitClbk`` function passed to the ``Nrf::Matter::PrepareServer`` function in the :file:`app_task.cpp` file should be modified to call additionally the ``gSimpleAttributePersistence.Init(Nrf::Matter::GetPersistentStorageDelegate())``.
71+
4372

4473
Thread
4574
------

samples/matter/common/src/app/matter_init.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,4 +437,9 @@ FactoryDataProviderBase *GetFactoryDataProvider()
437437
}
438438
#endif
439439

440+
PersistentStorageDelegate * GetPersistentStorageDelegate()
441+
{
442+
return sLocalInitData.mServerInitParams->persistentStorageDelegate;
443+
}
444+
440445
} /* namespace Nrf::Matter */

samples/matter/common/src/app/matter_init.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <app/clusters/network-commissioning/network-commissioning.h>
1313
#include <app/server/Server.h>
1414
#include <lib/core/Optional.h>
15+
#include <lib/core/CHIPPersistentStorageDelegate.h>
1516
#include <lib/support/Variant.h>
1617
#include <platform/PlatformManager.h>
1718

@@ -128,4 +129,6 @@ CHIP_ERROR StartServer();
128129
chip::DeviceLayer::FactoryDataProviderBase *GetFactoryDataProvider();
129130
#endif
130131

132+
chip::PersistentStorageDelegate * GetPersistentStorageDelegate();
133+
131134
} /* namespace Nrf::Matter */

samples/matter/light_bulb/src/app_task.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,9 @@ void AppTask::InitPWMDDevice()
290290
CHIP_ERROR AppTask::Init()
291291
{
292292
/* Initialize Matter stack */
293-
ReturnErrorOnFailure(Nrf::Matter::PrepareServer(Nrf::Matter::InitData{ .mPostServerInitClbk = [] {
293+
ReturnErrorOnFailure(Nrf::Matter::PrepareServer(Nrf::Matter::InitData{ .mPostServerInitClbk = []() {
294294
app::SetAttributePersistenceProvider(&gDeferredAttributePersister);
295+
gSimpleAttributePersistence.Init(Nrf::Matter::GetPersistentStorageDelegate());
295296
return CHIP_NO_ERROR;
296297
} }));
297298

samples/matter/light_bulb/src/zcl_callbacks.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ void emberAfOnOffClusterInitCallback(EndpointId endpoint)
8181

8282
/* Read storedValue on/off value */
8383
status = Attributes::OnOff::Get(endpoint, &storedValue);
84+
8485
if (status == Protocols::InteractionModel::Status::Success) {
8586
/* Set actual state to the cluster state that was last persisted */
8687
#if defined(CONFIG_PWM)

0 commit comments

Comments
 (0)