<?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>otSetStateChangedCallback () doesnt seem to register the callback.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/112335/otsetstatechangedcallback-doesnt-seem-to-register-the-callback</link><description>Hi, 
 In my app I have been using the following to register my state change callback. This works. Only issue is it seem to only pass ot_instance, I cant pass a user data to the callback. 
 
 openthread_set_state_changed_cb (on_thread_state_changed) 
</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 30 Jun 2024 23:28:51 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/112335/otsetstatechangedcallback-doesnt-seem-to-register-the-callback" /><item><title>RE: otSetStateChangedCallback () doesnt seem to register the callback.</title><link>https://devzone.nordicsemi.com/thread/491463?ContentTypeID=1</link><pubDate>Sun, 30 Jun 2024 23:28:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:804a909f-4152-4dcd-90ad-04f6da83c386</guid><dc:creator>kaushalyasat</dc:creator><description>&lt;p&gt;Thanks AHaug for your support. I have closed this ticket.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Kaushalya&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: otSetStateChangedCallback () doesnt seem to register the callback.</title><link>https://devzone.nordicsemi.com/thread/491336?ContentTypeID=1</link><pubDate>Fri, 28 Jun 2024 12:49:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fd85cea0-54a8-4f75-980e-66acd02786f2</guid><dc:creator>AHaug</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve had a look at your solution and discussed it with some of my colleagues and we both agree that what you&amp;#39;ve done looks like it should be working fine.&lt;/p&gt;
&lt;p&gt;Feel free to raise a new case or ask follow up questions in case you have any new questions&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Andreas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: otSetStateChangedCallback () doesnt seem to register the callback.</title><link>https://devzone.nordicsemi.com/thread/490651?ContentTypeID=1</link><pubDate>Tue, 25 Jun 2024 12:58:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9a2fece4-2ce3-45dd-9b93-19a7e43ad439</guid><dc:creator>AHaug</dc:creator><description>&lt;p&gt;Hi Kaushalya,&lt;/p&gt;
&lt;p&gt;Marte is currently on vacation so I will pick up this case while they are out of office. I need some time to sync up with the information here, but I will get back to you.&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Andreas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: otSetStateChangedCallback () doesnt seem to register the callback.</title><link>https://devzone.nordicsemi.com/thread/490129?ContentTypeID=1</link><pubDate>Mon, 24 Jun 2024 01:06:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:75a94eaa-d27e-4f4b-b5ad-5f9d33cdb6d8</guid><dc:creator>kaushalyasat</dc:creator><description>&lt;p&gt;Hi Marte,&lt;/p&gt;
&lt;p&gt;I think I managed to solve it by doing the following. I remember I have tried it like this initially and it didn&amp;#39;t work. Anyway, would like to know your opinion about the implementation.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void on_thread_state_changed(otChangedFlags flags, struct openthread_context *ot_context, void *user_data) {
    userdata *aUserdata = (userdata*) user_data;
    .
    .
}

void main () {
    .
    .
	static struct openthread_state_changed_cb ot_state_change_cb;

	ot_state_change_cb.user_data = &amp;amp;aUserData;
	ot_state_change_cb.state_changed_cb = on_thread_state_changed;
	openthread_state_changed_cb_register (openthread_get_default_context(), &amp;amp;ot_state_change_cb);

	error = openthread_start(openthread_get_default_context());
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;What I have done is to invoke the&amp;nbsp;openthread_state_changed_cb_register () &lt;span style="color:#993300;"&gt;&lt;strong&gt;before&lt;/strong&gt;&lt;/span&gt; I call&amp;nbsp;openthread_start ().&lt;/p&gt;
&lt;p&gt;Also I modified the signature of the callback. This callback seems to take a void *user_data, so I can successfully pass my user_data struct.&lt;/p&gt;
&lt;p&gt;Please let me know if this implementation is acceptable.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Kaushalya&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: otSetStateChangedCallback () doesnt seem to register the callback.</title><link>https://devzone.nordicsemi.com/thread/490125?ContentTypeID=1</link><pubDate>Sun, 23 Jun 2024 23:46:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:297671bc-7110-4379-b5dc-373ea8499710</guid><dc:creator>kaushalyasat</dc:creator><description>&lt;p&gt;Hi Marte, Sorry, I accidently closed this thread.&lt;/p&gt;
[quote userid="92402" url="~/f/nordic-q-a/112335/otsetstatechangedcallback-doesnt-seem-to-register-the-callback/489898"]Are you registering the callback with both openthread_set_state_changed_cb() and otSetStateChangedCallback()?[/quote]
&lt;p&gt;No I used one at a time. This is how I first tried the&amp;nbsp;openthread_state_changed_cb_register (...)&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void on_thread_state_changed(uint32_t flags, void *context) {
    struct openthread_context *ot_context = context;
    .
    .
}

void main () {
    .
    .
    struct openthread_state_changed_cb ot_state_change_cb;
    ot_state_change_cb.user_data = &amp;amp;aUserData;
    ot_state_change_cb.state_changed_cb = on_thread_state_changed;

    error = openthread_start(openthread_get_default_context());
    openthread_state_changed_cb_register (openthread_get_default_context(), &amp;amp;ot_state_change_cb);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;After failing to invoke the callback, I tried&amp;nbsp;otSetStateChangedCallback(...) as follows.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void on_thread_state_changed(uint32_t flags, void *context) {
    struct openthread_context *ot_context = context;
    .
    .
}

void main () {
.
.

    error = openthread_start(openthread_get_default_context());
    error = otSetStateChangedCallback (openthread_get_default_context(), on_thread_state_changed, &amp;amp;aUserData);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Neither seem to work. Only thing seemed to worked was the original&amp;nbsp;&lt;span&gt;openthread_set_state_changed_cb&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;on_thread_state_changed&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Also one other thing I am not clear about is how the aUserData is passed in the callback&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;on_thread_state_changed&amp;nbsp;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;uint32_t&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;flags&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;void&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt;context&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;void&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt;aContex&lt;/span&gt;&lt;span&gt;) as aContext is used to pass the&amp;nbsp;&lt;/span&gt;ot_context. The&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;ot_context doesnt have any member to carry user data. The typedef of the openthread state change callback function doesnt have any other void * to pass &amp;amp;aUserData.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;I am using SDK 2.3.0.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Cheers,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Kaushalya&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: otSetStateChangedCallback () doesnt seem to register the callback.</title><link>https://devzone.nordicsemi.com/thread/489898?ContentTypeID=1</link><pubDate>Fri, 21 Jun 2024 09:27:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:451a7890-6aa6-4bd3-89dd-da6a6c9f96e4</guid><dc:creator>Marte Myrvold</dc:creator><description>&lt;p&gt;Hi Kaushalya,&lt;/p&gt;
&lt;p&gt;Are you registering the callback with both openthread_set_state_changed_cb() and otSetStateChangedCallback()? You should only register the callback with one of these.&lt;/p&gt;
&lt;p&gt;What is it you want to achieve by sending user data to the state change callback?&lt;/p&gt;
&lt;p&gt;Please note that openthread_set_state_changed_cb() is deprecated, and you should use openthread_state_changed_cb_register() instead.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Marte&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>