Hi,
I can successfully start commissioning role when I use cli and the leader gets the commissioner active state. But when I try the same using API all, the leader gets stuck in the petition state. Following is what I did in my software.
// custom cli command to start commissioning otError cli_cmsn (void *aContext, uint8_t aArgsLength, char *aArgs[]) { otOperationalDataset aDataset; otError error; otInstance *instance = openthread_get_default_instance(); if (instance == NULL) { otCliOutputFormat ("get instantace error"); return OT_ERROR_FAILED; } otCliOutputFormat ("\n\r ifconfig down "); error = otIp6SetEnabled(instance, false); // ifconfig down if (error != OT_ERROR_NONE) { otCliOutputFormat ("ifconfig down error"); return (error); } otCliOutputFormat ("\n\r Thread stop "); error = otThreadSetEnabled (instance, false); // thread stop if (error != OT_ERROR_NONE) { otCliOutputFormat ("thread stop error"); return (error); } otCliOutputFormat ("\n\rCreate new dataset "); error = otDatasetCreateNewNetwork(instance, &aDataset); // create new dataset if (error != OT_ERROR_NONE) { otCliOutputFormat ("create new dataset error"); return (error); } otCliOutputFormat ("\n\r active new dataset "); error = otDatasetSetActive(instance, &aDataset); // active new dataset if (error != OT_ERROR_NONE) { otCliOutputFormat ("active new dataset error"); return (error); } otCliOutputFormat ("\n\r ifconfig up "); error = otIp6SetEnabled(instance, true); // ifconfig up if (error != OT_ERROR_NONE) { otCliOutputFormat ("ifconfig up error"); return (error); } otCliOutputFormat ("\n\r thread start "); error = otThreadSetEnabled (instance, true); // thread start if (error != OT_ERROR_NONE) { otCliOutputFormat ("thread start error"); return (error); } // spawn a thread to handle wait to connect to network k_tid_t my_tid = k_thread_create(&cmsn_thread_data, cmsn_stack_area, K_THREAD_STACK_SIZEOF(cmsn_stack_area), cmsn_handler, NULL, NULL, NULL, CMSN_THREAD_PRIORITY, 0, K_NO_WAIT); return (OT_ERROR_NONE); } // Thread handler to busy wait ot role change void cmsn_handler (void *, void *, void *) { otError error; while (ot_connected == true) { otCliOutputFormat ("."); k_msleep (500); } while (ot_connected == false) { otCliOutputFormat ("."); k_msleep (500); } otInstance *instance = openthread_get_default_instance(); otCliOutputFormat ("\n\r commissioner start "); error = otCommissionerStart (instance, aStateCallback, aJoinerCallback, NULL); if (error != OT_ERROR_NONE) { otCliOutputFormat ("commissioner start error %d\n\r", error); return (error); } }
I use a thread to busy wait till thread instance is back in router or leader role. The bool 'ot_connected' will be true when the role changes to router/leader.
I have only one device (leader) in this network. I have waited till device role becomes leader as well, but same result. But if I manually start using cli command 'commissioner start', it works.
How to solve this?
Cheers,
Kaushalya