Multicast CoAP request

814 views
Skip to first unread message

KOUDA MOHAMED AMINE

unread,
Apr 16, 2017, 3:52:06 AM4/16/17
to openthread-users
I am having problem with the CoAP multicast requests. The problem is when i use the "multicast" address instead of the "unicast", i can ping the server but the CoAP request doesn't reach the server. I used the same request, i just changed the address. Any suggestion?

Jonathan Hui

unread,
Apr 17, 2017, 9:08:38 PM4/17/17
to KOUDA MOHAMED AMINE, openthread-users
CoAP should work fine with multicast in OpenThread.  Thread uses multicast addressing with CoAP for its control messages in a number of different use cases, so that functionality has been tested and certified.

Can you provide more information on your environment and setup?  Can you provide pointers to you code?

--
Jonathan Hui

On Sun, Apr 16, 2017 at 12:52 AM, KOUDA MOHAMED AMINE <kouda...@gmail.com> wrote:
I am having problem with the CoAP multicast requests. The problem is when i use the "multicast" address instead of the "unicast", i can ping the server but the CoAP request doesn't reach the server. I used the same request, i just changed the address. Any suggestion?

--
You received this message because you are subscribed to the Google Groups "openthread-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openthread-users+unsubscribe@googlegroups.com.
To post to this group, send email to openthread-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openthread-users/e7cc0173-7bf9-4640-ace2-2692f7cdc6b9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

KOUDA MOHAMED AMINE

unread,
Apr 18, 2017, 3:21:08 AM4/18/17
to openthread-users
like i said , the multicast ping works , but the coap request doesnt reach the server i dont know the reason.
1- i used the code posted by OpenThread-based SDK   ( the thread client "multicast light send") .
 if i change the address to unicast one , it works.

Yakun Xu

unread,
Apr 18, 2017, 3:42:34 AM4/18/17
to openthread-users

What unicast address do you use?
What multicast address do you use?
Are you running the example code without modification, otherwise could you please post your code here?

KOUDA MOHAMED AMINE

unread,
Apr 18, 2017, 3:57:17 AM4/18/17
to openthread-users
1- unicast "fdde:ad00:beef:0:7de4:5af4:b2a5:fa9a"
2-  multicast "FF03::1"
3- the client:

void multicast_core_request_send(otInstance * p_instance)
.......
        otCoapHeaderInit(&header, kCoapTypeNonConfirmable, kCoapRequestGet);
        otCoapHeaderAppendUriPathOptions(&header, URI_PATH_CORE);                 // ***    /.well-known/core
        otCoapHeaderSetPayloadMarker(&header);

        p_message = otCoapNewMessage(p_instance, &header);
    

        error = otMessageAppend(p_message);

        if (error != kThreadError_None)
        {
            break;
        }

        memset(&messageInfo, 0, sizeof(messageInfo));
        messageInfo.mInterfaceId = OT_NETIF_INTERFACE_ID_THREAD;
        messageInfo.mPeerPort = OT_DEFAULT_COAP_PORT;
        otIp6AddressFromString("FF03::1", &messageInfo.mPeerAddr);
        error = otCoapSendRequest(p_instance, p_message, &messageInfo,NULL,p_instance);
   .............
  and the server :
otIp6Address *madd; 
const char *maddr ="ff03::1";
otIp6AddressFromString(maddr, &madd);
otIp6SubscribeMulticastAddress(aInstance, &madd);

Yakun Xu

unread,
Apr 18, 2017, 4:05:30 AM4/18/17
to openthread-users
In the server side code, the second parameter of otIp6AddressFromString should be a pointer to otIp6Address. Besides, I think OpenThread by default subscribe FF03::1.

KOUDA MOHAMED AMINE

unread,
Apr 18, 2017, 4:25:30 AM4/18/17
to openthread-users
if i verify in the server side with the cli commands i can find the FF03::1 ( ipmaddr ; after using this code);
is there any command for enabling multicast for the coap layer. or i did something wrong.
because the same code works perfectly for unicast. is there any changes to do when i change the address to multicast.

Yakun Xu

unread,
Apr 18, 2017, 4:42:17 AM4/18/17
to openthread-users
1. You do not need to subscribe FF03::1, because it's subscribed by default.
2. In the server code you posted, I noticed otIp6AddressFromString was passed in a wrong argument madd.

With your code, the server successfully subscribed the address, but since madd is pointed to somewhere unknown, it may cause those memory be override, which may result in node behaving unexpectedly. Please check your code carefully and correct the issue 2 and try again.
otIp6Address *madd;   ->  otIp6Address madd;

Besides, I also did simple experiment, which shows that the multicast for CoAP works fine.

KOUDA MOHAMED AMINE

unread,
Apr 18, 2017, 5:10:00 AM4/18/17
to openthread-users
i correct the issue but nothing happened. can you send me the multicast experiment's code that you have done.
may be i will find the problem with my code.

Yakun Xu

unread,
Apr 18, 2017, 10:35:06 PM4/18/17
to openthread-users
Below implements a simple echo service.

Server Code:

#include <stdio.h>
void handleRequest(void *aContext, otCoapHeader *aHeader, otMessage *aMessage,
                                     const otMessageInfo *aMessageInfo)
{
    otInstance *instance = (otInstance*)aContext;
    otCoapHeader header;
    otCoapHeaderInit(&header, kCoapTypeAcknowledgment, kCoapResponseChanged);
    otCoapHeaderSetMessageId(&header, otCoapHeaderGetMessageId(aHeader));
    otCoapHeaderSetToken(&header, otCoapHeaderGetToken(aHeader), otCoapHeaderGetTokenLength(aHeader));
    otCoapHeaderSetPayloadMarker(&header);

    otMessage *message = otCoapNewMessage(instance, &header);
    uint16_t len = otMessageGetLength(aMessage);
    uint16_t offset = otMessageGetOffset(aMessage);
    while (offset < len)
    {
        printf("offset is %d\n", offset);
        char buf[16];
        int count = otMessageRead(aMessage, offset, buf, sizeof(buf));
        printf("count is %d\n", count);
        if (count < 0) break;
        otMessageAppend(message, buf, (uint16_t)count);
        offset += (uint16_t)count;
    }
    otCoapSendResponse(instance, message, aMessageInfo);
}

void serverStart(otInstance *aInstance)
{
    static otCoapResource resource = {
        "echo",
        handleRequest,
        0,
        0
    };
    resource.mContext = aInstance;
    otCoapServerAddResource(aInstance, &resource);
    otCoapServerStart(aInstance);
}

Client:
OpenThread's built-in coap client. You can find doc on https://github.com/openthread/openthread/tree/master/src/cli#coap-server-phase

KOUDA MOHAMED AMINE

unread,
Apr 20, 2017, 3:32:28 AM4/20/17
to openthread-users
thank you, but what i need is the client code. ( where the multicast request is defined ) .

Yakun Xu

unread,
Apr 20, 2017, 3:55:26 AM4/20/17
to openthread-users
Please refer below,

ThreadError Coap::ProcessClient(int argc, char *argv[])
{
   
ThreadError error = kThreadError_None;
    otMessage
*message = NULL;
    otMessageInfo messageInfo
;
    otCoapHeader header
;

   
// Default parameters
   
char coapUri[kMaxUriLength] = "test";
    otCoapType coapType
= kCoapTypeNonConfirmable;
    otCoapCode coapCode
= kCoapRequestGet;
    otIp6Address coapDestinationIp
;

   
VerifyOrExit(argc > 0, error = kThreadError_InvalidArgs);

   
// CoAP-Code
   
ConvertToLower(argv[0]);

   
if (strcmp(argv[0], "get") == 0)
   
{
        coapCode
= kCoapRequestGet;
   
}
   
else if (strcmp(argv[0], "post") == 0)
   
{
        coapCode
= kCoapRequestPost;
   
}
   
else if (strcmp(argv[0], "put") == 0)
   
{
        coapCode
= kCoapRequestPut;
   
}
   
else if (strcmp(argv[0], "delete") == 0)
   
{
        coapCode
= kCoapRequestDelete;
   
}
   
else
   
{
       
ExitNow(error = kThreadError_Parse);
   
}

   
// Destination IPv6 address
   
if (argc > 1)
   
{
       
SuccessOrExit(error = otIp6AddressFromString(argv[1], &coapDestinationIp));
   
}
   
else
   
{
       
ExitNow(error = kThreadError_InvalidArgs);
   
}

   
// CoAP-URI
   
if (argc > 2)
   
{
        strlcpy
(coapUri, argv[2], kMaxUriLength);
   
}
   
else
   
{
       
ExitNow(error = kThreadError_InvalidArgs);
   
}

   
// CoAP-Type
   
ConvertToLower(argv[3]);

   
if ((argc > 3) && (strcmp(argv[3], "con") == 0))
   
{
        coapType
= kCoapTypeConfirmable;
   
}

    otCoapHeaderInit
(&header, coapType, coapCode);
    otCoapHeaderGenerateToken
(&header, Thread::Coap::Header::kDefaultTokenLength);
   
SuccessOrExit(error = otCoapHeaderAppendUriPathOptions(&header, coapUri));
    otCoapHeaderSetPayloadMarker
(&header);

    message
= otCoapNewMessage(sInstance, &header);
   
VerifyOrExit(message != NULL, error = kThreadError_NoBufs);

   
// Embed content into message if given
   
if (argc > 4)
   
{
       
SuccessOrExit(error = otMessageAppend(message, argv[4], static_cast<uint16_t>(strlen(argv[4]))));
   
}

    memset
(&messageInfo, 0, sizeof(messageInfo));
    messageInfo
.mPeerAddr = coapDestinationIp;
    messageInfo
.mPeerPort = OT_DEFAULT_COAP_PORT;
    messageInfo
.mInterfaceId = OT_NETIF_INTERFACE_ID_THREAD;

   
if ((coapType == kCoapTypeConfirmable) || coapCode == kCoapRequestGet)
   
{
        error
= otCoapSendRequest(sInstance, message, &messageInfo,
                                 
(otCoapResponseHandler) &Coap::s_HandleClientResponse, NULL);
   
}
   
else
   
{
        error
= otCoapSendRequest(sInstance, message, &messageInfo, NULL, NULL);
   
}

    sServer
->OutputFormat("Sending CoAP message: ");

exit:

   
if ((error != kThreadError_None) && (message != NULL))
   
{
        otMessageFree
(message);
   
}

   
return error;
}





KOUDA MOHAMED AMINE

unread,
Apr 20, 2017, 4:00:32 AM4/20/17
to openthread-users
thank you,



Le dimanche 16 avril 2017 08:52:06 UTC+1, KOUDA MOHAMED AMINE a écrit :

KOUDA MOHAMED AMINE

unread,
Apr 21, 2017, 7:11:33 PM4/21/17
to openthread-users
i used the same code but it doesnt work (err code = 30) ,
but the CLI requests works !!!!!!! ( coap client get addr resource )

--
You received this message because you are subscribed to a topic in the Google Groups "openthread-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openthread-users/rY5-pRt4gOU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openthread-users+unsubscribe@googlegroups.com.

To post to this group, send email to openthread-users@googlegroups.com.

Yakun Xu

unread,
Apr 21, 2017, 9:31:43 PM4/21/17
to openthread-users
Since I don't have your source full code, could you please try

1. resolving all warnings if any,
2. running static analysis,
3. testing your code with posix simulator and debug with gdb.

With the simulator, you can check what packets are really going out from a node. Or you can give me more details of your source code.

On Saturday, April 22, 2017 at 7:11:33 AM UTC+8, KOUDA MOHAMED AMINE wrote:
i used the same code but it doesnt work (err code = 30) ,
but the CLI requests works !!!!!!! ( coap client get addr resource )
2017-04-20 9:00 GMT+01:00 KOUDA MOHAMED AMINE <kouda...@gmail.com>:
thank you,


Le dimanche 16 avril 2017 08:52:06 UTC+1, KOUDA MOHAMED AMINE a écrit :
I am having problem with the CoAP multicast requests. The problem is when i use the "multicast" address instead of the "unicast", i can ping the server but the CoAP request doesn't reach the server. I used the same request, i just changed the address. Any suggestion?

--
You received this message because you are subscribed to a topic in the Google Groups "openthread-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openthread-users/rY5-pRt4gOU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openthread-use...@googlegroups.com.
To post to this group, send email to openthre...@googlegroups.com.

KOUDA MOHAMED AMINE

unread,
Apr 22, 2017, 4:01:14 PM4/22/17
to openthread-users
ok, i sent the source code to your email.

Le dimanche 16 avril 2017 08:52:06 UTC+1, KOUDA MOHAMED AMINE a écrit :

KOUDA MOHAMED AMINE

unread,
Apr 23, 2017, 5:43:38 AM4/23/17
to openthread-users
hi, Yakun
i sent you the source full code in your email. can you take a look please ?


Le dimanche 16 avril 2017 08:52:06 UTC+1, KOUDA MOHAMED AMINE a écrit :

Yakun Xu

unread,
Apr 23, 2017, 6:14:19 AM4/23/17
to openthre...@googlegroups.com
Where's function.h? I cannot compile.

I just checked the code, for client.c, I don't
1. line 224~231 is not needed.
2. If no payload for the request, line 217 is not needed.

KOUDA MOHAMED AMINE

unread,
Apr 23, 2017, 7:42:18 AM4/23/17
to openthread-users
sorry, i forgot it, i sent  the full one this time .


Le dimanche 16 avril 2017 08:52:06 UTC+1, KOUDA MOHAMED AMINE a écrit :

KOUDA MOHAMED AMINE

unread,
Apr 23, 2017, 10:41:34 AM4/23/17
to openthread-users
did you receive the files ?? yakun .



Le dimanche 16 avril 2017 08:52:06 UTC+1, KOUDA MOHAMED AMINE a écrit :

Yakun Xu

unread,
Apr 23, 2017, 10:51:33 AM4/23/17
to openthread-users
Yes, I didn't see attributes in definition of otCoapResource. Is this added by your self?

I tried to delay sending the request, the server can get the request.
    int i = 0;
    while (1)
    {
#if 1
        i++;
        printf("i = %d\n", i);
        if (i == 20) {
            multicast_core_request_send(sInstance, 1);
        }
#endif

You may have a try.

Yakun Xu

unread,
Apr 23, 2017, 11:04:33 AM4/23/17
to openthread-users
did you recompile the OpenThread source code with your changes to otCoapResource?

KOUDA MOHAMED AMINE

unread,
Apr 23, 2017, 11:09:58 AM4/23/17
to openthread-users
yes i did, and it works fine. the problem is just with the multicast,  because if you change the address in the request to a unicast one it will work


Le dimanche 16 avril 2017 08:52:06 UTC+1, KOUDA MOHAMED AMINE a écrit :

Yakun Xu

unread,
Apr 23, 2017, 11:23:46 AM4/23/17
to openthread-users
I've sent you what I used to test. I hope it can help you.

Besides, It's very appreciated that if you could contribute the attribute feature back to OpenThread. https://github.com/openthread/openthread

KOUDA MOHAMED AMINE

unread,
Apr 23, 2017, 11:29:34 AM4/23/17
to openthread-users
1- with the delay the server can receive the request YES :) , how can i used it just once.
2- i added the "attribute" field because i didnt find where to put them, because in contiki for example we can store the description. do you suggest that it's an important thing for contribution ?


Le dimanche 16 avril 2017 08:52:06 UTC+1, KOUDA MOHAMED AMINE a écrit :

Yakun Xu

unread,
Apr 23, 2017, 11:43:37 AM4/23/17
to openthread-users
1. I don't quite understand your meaning. That code only send once. If you want make it more elegant, you may use a timer of your platform.
2. Contribution is welcome.

KOUDA MOHAMED AMINE

unread,
Apr 23, 2017, 7:38:19 PM4/23/17
to openthread-users
it works fine thank you,
did you use such timer for CLI example. because i dont know how to make it.

KOUDA MOHAMED AMINE

unread,
Apr 24, 2017, 4:13:28 AM4/24/17
to openthread-users
hi yakun;
1- please do you have any example of timer usage on CLI example ?

Yakun Xu

unread,
Apr 24, 2017, 4:31:20 AM4/24/17
to openthread-users
The mainloop of CLI example didn't exposes timer function. You may implement your own mainloop supporting timer other task scheduling features based on your platform.

KOUDA MOHAMED AMINE

unread,
Apr 25, 2017, 3:13:35 AM4/25/17
to openthread-users
i have another question Yakun
1- how can i know the network topology ( for example how can i make my own scenario with CLI , for example a node must send his message through an intermediary to reach the other node) .  is it possible by using white and black lists or  previligied routes ?? and how ?
2-i didnt understand how to make a timer for example when a multicast request is received by to nodes simultanuously how can i make them replying in differents times ( i tried with random and sleep but is it correct ?? )


thank you so much for your support.

Yakun Xu

unread,
Apr 25, 2017, 9:39:30 AM4/25/17
to openthread-users
1- Try this https://github.com/openthread/openthread/tree/master/src/cli#whitelist
2- I don't think it's necessary to worry how node responds.

KOUDA MOHAMED AMINE

unread,
Apr 25, 2017, 10:07:28 AM4/25/17
to openthread-users
can i specify for each end-device which node is its parent ??  with this i can be sure that at least the communication will pass through one parent to reach the destination device.

Yakun Xu

unread,
Apr 25, 2017, 10:12:17 AM4/25/17
to openthread-users
You may use the whitelist/blacklist tech to form a expected network. I think the test scripts in OpenThread repo is good reference. https://github.com/openthread/openthread/tree/master/tests/scripts/thread-cert 

KOUDA MOHAMED AMINE

unread,
Apr 25, 2017, 11:22:00 AM4/25/17
to openthread-users
so if i want to send request from node1 to node3 passing through node2 , i add a node2 to the whitelist of node1 ??  should i blacklist node3 on node1 ? or the first step is sufficient.

Jonathan Hui

unread,
Apr 25, 2017, 11:53:06 AM4/25/17
to KOUDA MOHAMED AMINE, openthread-users
Note that Thread requires end devices to communicate only its parent.  In other words, end devices cannot communicate directly with other end devices.

--
Jonathan Hui

On Mon, Apr 17, 2017 at 6:08 PM Jonathan Hui <jon...@nestlabs.com> wrote:
CoAP should work fine with multicast in OpenThread.  Thread uses multicast addressing with CoAP for its control messages in a number of different use cases, so that functionality has been tested and certified.

Can you provide more information on your environment and setup?  Can you provide pointers to you code?

--
Jonathan Hui


On Sun, Apr 16, 2017 at 12:52 AM, KOUDA MOHAMED AMINE <kouda...@gmail.com> wrote:
I am having problem with the CoAP multicast requests. The problem is when i use the "multicast" address instead of the "unicast", i can ping the server but the CoAP request doesn't reach the server. I used the same request, i just changed the address. Any suggestion?

--
You received this message because you are subscribed to the Google Groups "openthread-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openthread-use...@googlegroups.com.

To post to this group, send email to openthre...@googlegroups.com.

KOUDA MOHAMED AMINE

unread,
Apr 25, 2017, 9:08:54 PM4/25/17
to openthread-users
so if i understood your explanation, i need to create some MTD end-device (children) + some FTD ones, and than add each parent to the wanted whitelist.
is that correct ?


Le dimanche 16 avril 2017 08:52:06 UTC+1, KOUDA MOHAMED AMINE a écrit :

Jonathan Hui

unread,
Apr 26, 2017, 1:38:36 AM4/26/17
to KOUDA MOHAMED AMINE, openthread-users
Correct.  But to my earlier point, if your only goal is to require traffic to traverse a Parent, then the whitelist is not necessary (all traffic from end devices must traverse a parent).

--
Jonathan Hui


--
You received this message because you are subscribed to the Google Groups "openthread-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openthread-use...@googlegroups.com.
To post to this group, send email to openthre...@googlegroups.com.

KOUDA MOHAMED AMINE

unread,
Apr 26, 2017, 2:24:53 AM4/26/17
to openthread-users
No, what i need really is to define the network topology ( the mesh ) .
so i want to send two-hops messages !! node1--->node4   passing through node 2  and node 3 for example. even if the source isnt an end-device it can be a router.

KOUDA MOHAMED AMINE

unread,
Apr 26, 2017, 4:19:06 AM4/26/17
to openthread-users

​how can i make something like this ( even without border routers )  ??

--
You received this message because you are subscribed to a topic in the Google Groups "openthread-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openthread-users/rY5-pRt4gOU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openthread-users+unsubscribe@googlegroups.com.
To post to this group, send email to openthread-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openthread-users/e094e979-90d8-4dfc-a188-dd8566183e52%40googlegroups.com.

KOUDA MOHAMED AMINE

unread,
Apr 26, 2017, 10:42:46 AM4/26/17
to openthread-users
is that possible ??

Yakun Xu

unread,
Apr 26, 2017, 10:46:28 AM4/26/17
to openthread-users
As I mentioned in last message, you can use the whitelist/blacklist feature to form the topology you want. You may learn from those test scripts of OpenThread. 


On Wednesday, April 26, 2017 at 10:42:46 PM UTC+8, KOUDA MOHAMED AMINE wrote:
is that possible ??

2017-04-26 9:19 GMT+01:00 KOUDA MOHAMED AMINE <kouda...@gmail.com>:

​how can i make something like this ( even without border routers )  ??
2017-04-26 7:24 GMT+01:00 KOUDA MOHAMED AMINE <kouda...@gmail.com>:
No, what i need really is to define the network topology ( the mesh ) .
so i want to send two-hops messages !! node1--->node4   passing through node 2  and node 3 for example. even if the source isnt an end-device it can be a router.
 
 
Le dimanche 16 avril 2017 08:52:06 UTC+1, KOUDA MOHAMED AMINE a écrit :
I am having problem with the CoAP multicast requests. The problem is when i use the "multicast" address instead of the "unicast", i can ping the server but the CoAP request doesn't reach the server. I used the same request, i just changed the address. Any suggestion?

--
You received this message because you are subscribed to a topic in the Google Groups "openthread-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openthread-users/rY5-pRt4gOU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openthread-use...@googlegroups.com.
To post to this group, send email to openthre...@googlegroups.com.

KOUDA MOHAMED AMINE

unread,
Apr 26, 2017, 11:07:30 AM4/26/17
to openthread-users
is there a specific one that i should take a look on it ??
Message has been deleted
Message has been deleted
Message has been deleted

KOUDA MOHAMED AMINE

unread,
May 8, 2017, 5:56:35 AM5/8/17
to openthread-users
hello ,
1- when the client sends a multicast coap request   (ff33:40:fdde:ad00:beef:0:0:1) (all devices are subscribed to this multicast address)
 it reaches all the thread nodes  and they reply . But the client receives responses from one node only.  even when i make it two or three times.   i tried it with  ( 1 client and  3 servers )  .

Reply all
Reply to author
Forward
0 new messages