Coap client not triggering handler for observed resource

I am using:

NCS 3.0.1
nRF52840DK

My project is based on the coap_client sample, currently running on a nRF52840DK.  I have modified it to add the 'observe' option in the request to the server.  The response handler is invoked when the server responds to the original request.  However, the client returns a Reset message to later notifications from the server, and does not invoke the response handler.

I have implemented observer functionality on the client using NCS 2.4.1, and when I compile this project for NCS 2.4.1, the client sends an ACK to the server when it receives a notifications.

The server is implemented on a Raspberry Pi (with OTBR) using libcoap.

In prf.conf

# Enable OpenThread CoAP support API
CONFIG_OPENTHREAD_COAP=y
CONFIG_OPENTHREAD_COAP_OBSERVE=y
static void send_dustsensor_request(struct k_work *item)
{
	ARG_UNUSED(item);

	LOG_INF("Send 'dustsensor' GET request \r\n");

	if (g_server_addr.mFields.m8[0] == 0) {
 		LOG_WRN("Peer address not set. Can't send dustsensor get");
 		return;
 	}

	poll_period_response_set();
	
	ot_coap_send_request(OT_COAP_CODE_GET, &g_server_addr, dustsensor_option, 
		(uint8_t *)&g_eui64, sizeof(g_eui64), 
		on_dustsensor_reply, 1, 0);												// observe
}

otError ot_coap_send_request(enum otCoapCode code, otIp6Address *addr,const char *uri_path, 
			uint8_t *payload, uint16_t payload_size, 
			otCoapResponseHandler reply_cb, bool observe_option, uint32_t observe_flag)
{
	otError error = OT_ERROR_NO_BUFS;
	otMessage *request;
    otInstance *instance;
    otMessageInfo message_info;

    instance = openthread_get_default_instance();

	request = otCoapNewMessage(instance, NULL);
	if (request == NULL) {
		goto end;
	}

    memset(&message_info, 0, sizeof(otMessageInfo));
    memcpy(&(message_info.mPeerAddr), addr, sizeof(otIp6Address)); 
    message_info.mPeerPort = OT_DEFAULT_COAP_PORT;

	otCoapMessageInit(request, OT_COAP_TYPE_CONFIRMABLE, code);

    otCoapMessageGenerateToken(request, 8);

	// Options, must be in ascending order of option number
	if ((code == OT_COAP_CODE_GET) && observe_option)
	{
		//error = otCoapMessageAppendUintOption(request, OT_COAP_OPTION_OBSERVE, observe_flag);
		error = otCoapMessageAppendObserveOption(request, observe_flag);
		if (error != OT_ERROR_NONE)
			LOG_ERR("otCoapMessageAppendUintOption() returned %d", error);

	}

    error = otCoapMessageAppendUriPathOptions(request, uri_path);

 //   otCoapMessageAppendContentFormatOption(request, OT_COAP_OPTION_CONTENT_FORMAT_TEXT_PLAIN);

	// Payload
 	error = otCoapMessageSetPayloadMarker(request);
	if (error != OT_ERROR_NONE) {
		goto end;
	}

    if (payload != NULL)
    {
        error = otMessageAppend(request, payload, payload_size);
        if (error != OT_ERROR_NONE) {
            goto end;
        }
    }

	otCoapTxParameters txParms;
	txParms.mAckRandomFactorDenominator = 1.0;
	
 	error = otCoapSendRequest(instance, request, &message_info, reply_cb, NULL);
    LOG_INF("otCoapSendRequest() returned %d\r\n", error);

end:
	if (error != OT_ERROR_NONE && request != NULL) 
    {
		otMessageFree(request);
	}

	if (error == OT_ERROR_NO_BUFS)
		g_reboot = true;

	return error;

}
See attached Wireshark log.  
observed_resource_reset.pcapng
Frame 1458:  original request from client
Frame 1460: server response
Frame 1469: Server notification
Frame 1471:  RST from client
What's changed since 2.4.1?
How do I get debug log output from ot:coap?  I've included the 'debug' snippet, and the 'logging' snippet, but am not seeing an low level debug output.
Mary
  • Hi,

    What's changed since 2.4.1?
    I have implemented observer functionality on the client using NCS 2.4.1, and when I compile this project for NCS 2.4.1, the client sends an ACK to the server when it receives a notifications.

    Are you now using NCS v3.0.1 and having reset problem but everything worked fine in NCS v2.4.1?

    How do I get debug log output from ot:coap?  I've included the 'debug' snippet, and the 'logging' snippet, but am not seeing an low level debug output.

    How did you include snippets?
    For logging, you can look at OpenThread logging levels and Zephyr L2 logging options.

    Best regards,
    Dejan

  • Yes. Everything worked fine NCS 2.4.1.  The reset problem occurs with NCS 3.0.1.

    I included the snippets in the build configuration. (mtd, debugging, logging, ci).  Using the same snippets, I get a ton of debug log messages when I compile with NCS 2.4.1, but only application level logs with NCS 3.0.1.

    Mary

  • Hi Mary,

    Can you provide your network key so that we can look into your provided Wireshark file? Please let me know if there is any reason to make this case private with regard to sharing your key.

    Can you try to increase logging level using CONFIG_OPENTHREAD_LOG_LEVEL_DEBG?

    Best regards,
    Dejan

  • Network key: d2970b94e1eecfcb92fcdd3d825d5efd

    That logging level is already set.

    logging.conf

    # Option for configuring log level in Zephyr L2 logging
    CONFIG_OPENTHREAD_L2_DEBUG=y
    CONFIG_OPENTHREAD_L2_LOG_LEVEL_DBG=y
    # CONFIG_OPENTHREAD_L2_DEBUG_DUMP_15_4=y
    # CONFIG_OPENTHREAD_L2_DEBUG_DUMP_IPV6=y
    
    # Configure sample logging setting
    CONFIG_LOG=y
    CONFIG_COAP_CLIENT_LOG_LEVEL_DBG=y
    CONFIG_COAP_CLIENT_UTILS_LOG_LEVEL_DBG=y
    CONFIG_COAP_UTILS_LOG_LEVEL_DBG=y
    CONFIG_OPENTHREAD_DEBUG=y
    
    CONFIG_COAP_LOG_LEVEL_DBG=y
    
    # Adjust log strdup settings
    
    # Enable Mbed TLS logging
    # CONFIG_OPENTHREAD_MBEDTLS_DEBUG=y
    # CONFIG_MBEDTLS_DEBUG_LEVEL=3
    
    # Option for configuring log level in OpenThread
    #CONFIG_OPENTHREAD_LOG_LEVEL_NOTE=y
    CONFIG_OPENTHREAD_LOG_LEVEL_DEBG=y
    
    # Enable RTT logging backend
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_LOG_BACKEND_RTT=y
    
    # Disable UART logging backend
    CONFIG_LOG_BACKEND_UART=n
    CONFIG_SHELL_LOG_BACKEND=n
    

    Mary

  • Hi Mary,

    Thank you for providing your network key.

    I will look into it during next week.

    Best regards,
    Dejan

Related