I'm working with the OpenThread CoAP protocol in the nRF Connect SDK 2.0.0. I started with the samples:
\ncs\v2.0.0\nrf\samples\openthread\coap_client
\ncs\v2.0.0\nrf\samples\openthread\coap_server
I've added an Observable resource on the server, to which the client subscribes (registers) to be notified on updates. I have the following Kconfig options set:
CONFIG_OPENTHREAD_COAP=y
CONFIG_OPENTHREAD_COAP_OBSERVE=y
CONFIG_OPENTHREAD_COAP_OBSERVE=y
I've verified that these are set to 'y' in the following project build file:
\build\zephyr\.config
However, the server notifications that the Observed resource has changed do not result in the response callback on the client. In my call stack I see the OpenThread API functions are implemented in:
\ncs\v2.0.0\modules\lib\openthread\src\core\api\coap_api.cpp
Which calls into
\ncs\v2.0.0\modules\lib\openthread\src\core\coap\coap.cpp
In the latter "coap.cpp" file, the sections of code dealing with "Observe" support are conditionally compiled using
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
However, this is set to 0, and so these Observe code is not part of the build. If not already defined, it defaults to 0 in
\ncs\v2.0.0\modules\lib\openthread\src\core\config\coap.h
/**
* @def OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
*
* Define to 1 to enable the CoAP Observe (RFC7641) API.
*
*/
#ifndef OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
#define OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE 0
#endif
I determined it was not defaulting to 0, but was already defined as 0. However, I forced it to be set by changing the header file as follows:
/**
* @def OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
*
* Define to 1 to enable the CoAP Observe (RFC7641) API.
*
*/
//#ifndef OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
#define OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE 1
//#endif
After rebuilding with this change, the Observe notifications are properly calling the response callback on the client!!
So... how should the project configuration be set up so OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE is set??
It appears that either CONFIG_OPENTHREAD_COAP_OBSERVE=y is insufficient, or something else overrides it...