Networkkey error with Openthread

Im programming the Openthread coprocessor NCP Zephyr example on a nrf52840 and I am using nrf connect sdk 2.2.0. I just added logs to the sample, so it is really basic:

void main(void)

{

	otInstance *ot;

	otError error;

	uint16_t panid;

	uint8_t networkkey[16];

	uint8_t channel;

	otExtAddress *extAddr;

	otExtendedPanId *extPanId;

	otNetworkKey *networkKey;

	otOperationalDataset *dataset;

	const char *networkName;



	// LOG_INF("Running...");

	for (;;) {

		k_sleep(K_MSEC(1000));



		// Inicializar la instancia de OpenThread

		ot = otInstanceInitSingle();

		error = otDatasetGetActive(ot, dataset);

		// Obtener el PAN ID actual

		panid = otLinkGetPanId(ot);

		LOG_INF("PANID: %04X",panid);

		// Obtener el canal actual

		channel = otLinkGetChannel(ot);

		LOG_INF("Channel: %0d",channel);

		//Obtener el networkname

		// LOG_INF("Network Name: %c%c%c%c", 

		// dataset->mNetworkName.m8[0], dataset->mNetworkName.m8[1], dataset->mNetworkName.m8[2], dataset->mNetworkName.m8[3]);

		// Obtener la extended addr

		extAddr = otLinkGetExtendedAddress(ot);

		LOG_INF("MAC Addrs: %02X%02X%02X%02X%02X%02X%02X%02X",

		extAddr->m8[0], extAddr->m8[1], extAddr->m8[2], extAddr->m8[3],

		extAddr->m8[4], extAddr->m8[5], extAddr->m8[6], extAddr->m8[7]);

		// Obtener el extended PAN ID

		extPanId = otThreadGetExtendedPanId(ot);

		LOG_INF("ExtPANID: %02X%02X%02X%02X%02X%02X%02X%02X",

		extPanId->m8[0], extPanId->m8[1], extPanId->m8[2], extPanId->m8[3],

		extPanId->m8[4], extPanId->m8[5], extPanId->m8[6], extPanId->m8[7]);

		// Obtener el network key

		otThreadGetNetworkKey(ot, networkKey);

		LOG_INF("Networkkey: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",

		networkKey->m8[0], networkKey->m8[1], networkKey->m8[2], networkKey->m8[3],

		networkKey->m8[4], networkKey->m8[5], networkKey->m8[6], networkKey->m8[7],

		networkKey->m8[8], networkKey->m8[9], networkKey->m8[10], networkKey->m8[11],

		networkKey->m8[12], networkKey->m8[13], networkKey->m8[14], networkKey->m8[15]);

		// Obtener la network name

		networkName = otThreadGetNetworkName(ot);

		LOG_INF("Network Name: %s\n\n", networkName);
}

When I flash the radio co processor and the host its works nicely. But if I scan the openthread network i get the next output:



I have 3 nodes and that one marked is the one I am talking. The node with CLI mode is the one I am scanning from. We can observe that network name is not appearing and the extended PANid is not correct cause if I look at the logs I can see this:

(ignore the MAC addrs, this screen is from an old try)

So I have tried to change it from prj.conf:
CONFIG_OPENTHREAD_NETWORKKEY="00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff"

And when I build it, I check it in .config and it has been set correctly, but If I log it, the result is the same that I shared in the pictures above.

So my question is:
1º) Why is not appearing the network name when I scan from another node?

2º) Why in the logs I can see the correct extended panid but it is "0000000000000000" when I scan it?

3º) Why the networkkey is not the correct when I log it?

  • Hi,

    Im programming the Openthread coprocessor NCP Zephyr example on a nrf52840 and I am using nrf connect sdk 2.2.0.

    Can you confirm which of the following samples you are using?

    From your description, I believe you are using the second, but we recommend that you use the first sample.

    So my question is:
    1º) Why is not appearing the network name when I scan from another node?

    2º) Why in the logs I can see the correct extended panid but it is "0000000000000000" when I scan it?

    3º) Why the networkkey is not the correct when I log it?

    The network co-processor samples are intended to use together with a host, where the host typically will set the network parameters (or start the commissioning process). The Kconfig configurations might not be applied in this sample. Also, make sure that you erase the full chip before programming the sample. If there exist a dataset in flash from a previous run, the new configuration might not be applied by the application. Some code checks if a commissioned dataset exists before setting a new/default configuration.

    Do you test this together with the host? Can you try to do the logging at a later stage (for instance when you do the scanning), e.g. on a button press or similar?

    Best regards,
    Jørgen

Related