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 Children
  • Hi Sigurd, Many thanks for your efforts, highly appreciated. So the suggested way is to use IP6 from client message? How can we retrieve this info from message itself? Any API calls? 

    Thanks again,

  • Hi,

    One step closer: I am able to print the server IP from the client I think.

    From the provisioning coap command I were able to print the IP address as such:

    diff --git a/samples/openthread/coap_client/src/coap_client_utils.c b/samples/openthread/coap_client/src/coap_client_utils.c
    index 52772ace6..f86d0c725 100644
    --- a/samples/openthread/coap_client/src/coap_client_utils.c
    +++ b/samples/openthread/coap_client/src/coap_client_utils.c
    @@ -110,6 +110,13 @@ static int on_provisioning_reply(const struct coap_packet *response,
     
            payload = coap_packet_get_payload(response, &payload_size);
     
    +    char ipurd[40];
    +
    +    net_addr_ntop(AF_INET6, from, ipurd, sizeof(ipurd));
    +
    +    printk("AAAA %s AAA\n", ipurd);
    +    
    +
            if (payload == NULL ||
                payload_size != sizeof(unique_local_addr.sin6_addr)) {
                    LOG_ERR("Received data is invalid");
    

    Regards,
    Sigurd Hellesvik

  • 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,

  • 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