<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Receive CoAP Block messages on Thingy:53</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/93725/receive-coap-block-messages-on-thingy-53</link><description>Hello, 
 I am currently developing a CoAP client on the Thingy:53. For one task, the client has to send a request to a server on a Raspberry Pi which is based on the LibCoAP library and then gets a response with a payload. This works fine as long as the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 05 Dec 2022 14:10:56 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/93725/receive-coap-block-messages-on-thingy-53" /><item><title>RE: Receive CoAP Block messages on Thingy:53</title><link>https://devzone.nordicsemi.com/thread/399002?ContentTypeID=1</link><pubDate>Mon, 05 Dec 2022 14:10:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:adce93d8-b2db-426b-8ace-e270fd1fa849</guid><dc:creator>Charlie</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;You can find a reference implementation of BlockwiseReceiveHook from&amp;nbsp;&lt;a href="https://github.com/openthread/openthread/blob/main/src/cli/cli_coap.cpp#L887"&gt;openthread/cli_coap.cpp at main · openthread/openthread (github.com)&lt;/a&gt;&amp;nbsp;or directly test with &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.1.2/nrf/samples/openthread/cli/README.html"&gt;ot-cli commands sample&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;remember to&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.1.2/nrf/ug_thread_prebuilt_libs.html#id4"&gt;Updating pre-built OpenThread libraries&lt;/a&gt;&amp;nbsp;with&amp;nbsp;OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE enabled, since this configuration is disabled by default.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Charlie&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Receive CoAP Block messages on Thingy:53</title><link>https://devzone.nordicsemi.com/thread/398878?ContentTypeID=1</link><pubDate>Sun, 04 Dec 2022 12:54:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:20df0505-1e78-4a95-aef9-8c11ffd835b0</guid><dc:creator>sihess</dc:creator><description>&lt;p&gt;Hi, sorry for the late reply. Here some snippets of my code:&lt;/p&gt;
&lt;p&gt;This is the request I send from the Thingy:53 device to the server:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void get_request(struct k_work *item) {	
	
	ARG_UNUSED(item);

	otError 		error = OT_ERROR_NONE;
	otMessage 		*myMessage;
	otMessageInfo 	myMessageInfo;
	otInstance 		*myInstance = openthread_get_default_instance();
	
	LOG_INF(&amp;quot;Send &amp;#39;GET&amp;#39; request\n&amp;quot;);

	do{
		myMessage = otCoapNewMessage(myInstance, NULL);
		if (myMessage == NULL) {
			printk(&amp;quot;Failed to allocate message for CoAP Request\n&amp;quot;);
			return;
		}
		memset(&amp;amp;myMessageInfo, 0, sizeof(myMessageInfo));
		myMessageInfo.mPeerPort = OT_DEFAULT_COAP_PORT;
		otIp6AddressFromString(serverAddr, &amp;amp;myMessageInfo.mPeerAddr);
		if (error != OT_ERROR_NONE){ 
			printk(&amp;quot;IPv6 Error\n&amp;quot;);
			break;
		}

    	otCoapMessageInit(myMessage, OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_GET);
    

		otCoapMessageGenerateToken(myMessage, OT_COAP_DEFAULT_TOKEN_LENGTH);
		error = otCoapMessageAppendObserveOption(myMessage, 0);
		if (error != OT_ERROR_NONE){ 
			printk(&amp;quot;Append Observe Option Error\n&amp;quot;);
    	}
    	
    	error = otCoapMessageAppendUriPathOptions(myMessage, &amp;quot;uri-path&amp;quot;);
    	if (error != OT_ERROR_NONE){ 
    		printk(&amp;quot;URI PATH FAIL\n&amp;quot;);
    	}
    
    	error = otCoapMessageAppendContentFormatOption(myMessage, 
    										OT_COAP_OPTION_CONTENT_FORMAT_TEXT_PLAIN);
    	if (error != OT_ERROR_NONE){ 
    		printk(&amp;quot;Content Error\n&amp;quot;);
    	}
    	
    	error = otCoapMessageSetPayloadMarker(myMessage);
    	if (error != OT_ERROR_NONE){ 
    		printk(&amp;quot;Set Payload Marker Error\n&amp;quot;);
    	}
	
		if (error != OT_ERROR_NONE){ 
			printk(&amp;quot;CoAP message initialization error!\n&amp;quot;);
			break;
		}

		error = otCoapSendRequestBlockWise(myInstance, myMessage, &amp;amp;myMessageInfo,
											default_response_handler, NULL, NULL, BlockwiseReceiveHook);
	}
	while(false);

	if (error != OT_ERROR_NONE) {
		printk(&amp;quot;Failed to send GET request: %d\n&amp;quot;, error);
		otMessageFree(myMessage);
	}
	else{
		printk(&amp;quot;GET request sent success&amp;quot;);	
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And here the ReceiveHook function. This is currently just a test function to test if it even gets called:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;otError BlockwiseReceiveHook(void         *aContext,
							const uint8_t *aBlock,
							uint32_t       aPosition,
							uint16_t       aBlockLength,
							bool           aMore,
							uint32_t       aTotalLength)
{
	printk(&amp;quot;Receive Hook Function\n&amp;quot;);

	OT_UNUSED_VARIABLE(aContext);
    OT_UNUSED_VARIABLE(aMore);
    OT_UNUSED_VARIABLE(aTotalLength);

    return OT_ERROR_NONE;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;By using the debugger, I found out that the ReceiveHook gets called at the arrival of the message but then crashes somewhere in the code where the first block of the response gets handled.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am able to receive the block response with this CoAP client browser plugin, so the server seems to be able to send it properly:&amp;nbsp;&lt;a id="" href="https://github.com/mkovatsc/Copper"&gt;https://github.com/mkovatsc/Copper&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Thank you very much for your help!&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best wishes, Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Receive CoAP Block messages on Thingy:53</title><link>https://devzone.nordicsemi.com/thread/396194?ContentTypeID=1</link><pubDate>Thu, 17 Nov 2022 12:20:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:18fe41d2-2065-4c3b-af6d-f0f5076c3f2b</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Simon&lt;/p&gt;
&lt;p&gt;Are you able to share your code so we can try to reproduce the issue here?&lt;/p&gt;
&lt;p&gt;If you don&amp;#39;t want to share your code in a public ticket I can make the case private.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Charlie is on travel this week, but he&amp;nbsp;should&amp;nbsp;be back next week.&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Receive CoAP Block messages on Thingy:53</title><link>https://devzone.nordicsemi.com/thread/395568?ContentTypeID=1</link><pubDate>Mon, 14 Nov 2022 13:25:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:705fea12-fa32-44b6-a9bf-20eeebbe0b39</guid><dc:creator>sihess</dc:creator><description>&lt;p&gt;Hi Charlie&lt;/p&gt;
&lt;p&gt;Thanks for the fast reply. Yes, I already saw this post. The thing is however, that I try to receive a blockwise response from the server which is implemented with libcoap. This library provides a function that handles blockwise responses (&lt;a href="https://libcoap.net/doc/reference/develop/man_coap_add_data_large_response.html#coap_add_data_large_response"&gt;https://libcoap.net/doc/reference/develop/man_coap_add_data_large_response.html#coap_add_data_large_response&lt;/a&gt;). I am able to receive the first block of 1024 bytes. But when I add the receive hook function in the request, the nrf device crashes as soon as the response arrives.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Receive CoAP Block messages on Thingy:53</title><link>https://devzone.nordicsemi.com/thread/395062?ContentTypeID=1</link><pubDate>Thu, 10 Nov 2022 09:47:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4e6f2984-5e49-48ec-becb-f6a6577f505a</guid><dc:creator>Charlie</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;There are some discussions about this topic on&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/92333/sending-coap-block-wise-requests-ncs-2-0-0"&gt;(+) Sending CoAP Block-wise requests (NCS 2.0.0) - Nordic Q&amp;amp;A - Nordic DevZone - Nordic DevZone (nordicsemi.com)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Let me know if this helps.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Charlie&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>