How to identify two or more CoAP clients connected to the same Server

Hi, How can I get the RLOC16 or similar ID from the CoAP clients connected to my CoAP server? I need to get this information from the messages that the clients send. 

Cheers,

Parents Reply
  • I am greatly appreciating your efforts in solving this, thank you.

    This is done in the client isn't it? It looks like client is getting the server's IP? In my case I want to do the opposite. I need the server to figure out who sent the message. So looks like it should be initiated from the server, if possible. Now the servrer must be getting the clients address details, some for or the other. 

    Worst case I can encode the clients address info (Extended MAC?) in the application level packet, where I put my data to be send to the server. Then server can see that the same way it gets my data. This will extend my packet size and also power consumption, but to how much I have to test it. For that I need an API call for the client to get its own address like extended MAC. Can you point me to some thing like that?

    Thanks again,

Children
  • Hi,

    I think I solved it!

    Now that I know the solution, I feel like I should have found it earlier, but as they say "better late then never".

    I found the IP address in struct otMessageInfo.

    Here is some code for the coap server sample

    diff --git a/samples/openthread/coap_server/src/ot_coap_utils.c b/samples/openthread/coap_server/src/ot_coap_utils.c
    index 65f1dad17..83ce14f7e 100644
    --- a/samples/openthread/coap_server/src/ot_coap_utils.c
    +++ b/samples/openthread/coap_server/src/ot_coap_utils.c
    @@ -130,6 +130,11 @@ static void light_request_handler(void *context, otMessage *message,
            uint8_t command;
     
            ARG_UNUSED(context);
    +    char ipurd[OT_IP6_ADDRESS_STRING_SIZE]; 
    +    otIp6Address from = message_info->mPeerAddr;
    +    otIp6AddressToString(&from, ipurd, sizeof(ipurd));
    +
    +    printk("Peer IP: %s\n",ipurd);
     
            if (otCoapMessageGetType(message) != OT_COAP_TYPE_NON_CONFIRMABLE) {
                    LOG_ERR("Light handler - Unexpected type of message");
    

    Regards,
    Sigurd Hellesvik

Related