nRF52 Thread unicast mode ipaddr read and write

Hi, I am currently working on nRF52 Thread v4.1.0 .

I am working on messaging transferring using coAP server an client . 

previously using CLI commands to detect the ipaddr , ipaddr add, ipaddr del

i want to set the  static ipaddr for my devices . and without using cli commands i need to configure ipaddr

and also read and write the ipaddr using the functions

so where could I get those functions

and

where otIp6IsAddressUnspecified is located

got like this

Parents Reply Children
  • Hi Jørgen, Thanks for your reply.

    During initialization of Thread itself ipaddress is set?

    if so during that time itself we give static ipaddress or

    there should be 3 or 4 set of ipaddress will generate

    > ipaddr
    fdde:ad00:beef:0:0:ff:fe00:fc00
    fdde:ad00:beef:0:0:ff:fe00:5c00
    fdde:ad00:beef:0:c1f7:fe04:39ec:79ad
    fe80:0:0:0:3448:71b0:2147:7e41
    Done

    can we set only one ipaddr and it should be static is it possible

  • The addresses are assigned during different part of the initialization and/or network formation/attachment process. Some of the addresses are also dynamic, and may change during runtime if the Thread network change.

    I would recommend you to read about the different IPv6 addressing types in the OpenThread documentation.

    From your example output:

    • fe80:0:0:0:3448:71b0:2147:7e41 is the Link-Local Address (assigned during CLI command "ifconfig up")
    • fdde:ad00:beef:0:c1f7:fe04:39ec:79ad is the Mesh-Local EID address of the device. This address is not dependent on network topology, so this is the recommended address to use when you want to address a specific node.
    • fdde:ad00:beef:0:0:ff:fe00:5c00 is the Routing Locator (RLOC) address of the node, which is dependent on the nodes placement in the network. If the node changes it state to child, or REED, this address will change. The address may also change due to other changes in the network.
    • fdde:ad00:beef:0:0:ff:fe00:fc00 is the Anycast Locator for the network Leader node. If another node in the network takes over the role as leader, it will be assigned this address. The address will then disappear from this node (you can test this by adding another node to your network, it will have only the 3 above addresses)
  • Hi Jørgen,

    const char  * stat_ip = "FDDE::DEAD:BEEF:1002";
    int aArgsLength = 10;
    
    void ipaddrAdd()
    {
        otError        error;
        otNetifAddress aAddress;
    
        otInstance * mInstance = thread_ot_instance_get();   
        otIp6AddressFromString(stat_ip[0], &aAddress.mAddress);
        aAddress.mPrefixLength = 64;
        aAddress.mPreferred    = true;
        aAddress.mValid        = true;
        error                  = otIp6AddUnicastAddress(mInstance, &aAddress);
    }

    added these lines and call the ipaddrAdd() 

    under

    thread_instance_init();
    thread_coap_init();
    thread_bsp_init();
    ipaddrAdd();

    output is

    > 
    > ipaddr
    fdde:ad00:beef:0:0:ff:fe00:fc00
    fdde:ad00:beef:0:0:ff:fe00:c000
    0:0:0:0:0:0:0:0
    fdde:ad00:beef:0:263c:9c02:6ca0:1fb2
    fe80:0:0:0:a894:c859:4d2d:2302
    Done
    > 
    

  • Compiling your code gives warning about passing pointer from integer without cast to otIp6AddressFromString:

    warning: passing argument 1 of 'otIp6AddressFromString' makes pointer from integer without a cast [-Wint-conversion]

    Try passing stat_ip instead of stat_ip[0].

    This gives me this output:

    > ipaddr
    fdde:ad00:beef:0:0:ff:fe00:fc00
    fdde:ad00:beef:0:0:ff:fe00:dc00
    fdde:0:0:0:0:dead:beef:1002
    fdde:ad00:beef:0:fd05:418f:3d65:fc76
    fe80:0:0:0:4078:a2fb:2e53:a22a
    Done

Related