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,
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,
Hi Sigurd,
Thanks for your reply. Wouldn't this retrieve the RLOC of the server?
I tried the otThreadGetRloc16 () function, but it only got the RLOC16 of the server.
In my instance more than one coap clients will be sending messages to the server. So server needs to get the RLOC16 of each client based on each message.
My client handler in the server is like this
Cheers,
Hi,
kaushalyasat said:I tried the otThreadGetRloc16 () function, but it only got the RLOC16 of the server.
Ah right yes. I misunderstood the question.
For the child RLOC16:
On my OTBR I run "sudo ot-ctl child table" which gives me the following:

See child table.
This links to an API command that you should be able to call to get the RLOC value.
PS: You can also test these CLI commands using our OpenThread CLI sample.
Regards,
Sigurd Hellesvik
Hi,
kaushalyasat said:I tried the otThreadGetRloc16 () function, but it only got the RLOC16 of the server.
Ah right yes. I misunderstood the question.
For the child RLOC16:
On my OTBR I run "sudo ot-ctl child table" which gives me the following:

See child table.
This links to an API command that you should be able to call to get the RLOC value.
PS: You can also test these CLI commands using our OpenThread CLI sample.
Regards,
Sigurd Hellesvik
thanks, I am using the CLI commands to query the child table and other info. It is a great tool. I can trace that CLI uses 'otThreadGetChildInfoByIndex()' function to get 'childInfo.mRloc16'. But that does not help my case as I need to decode RLOC16 from the message itself to identify who send it. I can encode the client RLOC16 with the message itself, but that I feel like wasting radio bandwidth. I think definitely the senders RLOC16 (or some other address parameter) is available at app level based on the message. So what I am looking for is an API call to extract that from the message, inside the message handler.
Hi, Any reply to this? I think RLOC16 is not a static value which identifies the client accurately. So I am thinking of getting the extended MAC or something similar. Any idea?
Hi,
Sorry for the delay.
I were looking for a way to do this yesterday, but have not been able to do so yet.
I asked our developers about this, and this is what they said:
"
Notice that the RLOC16 is used by the child as MAC source address, by this is a Link Layer parameter, not propagated to the Application Layer (CoAP).
The customer should find better ways to identify the end point at an application level.
IPv6 are available at CoAP level, so that could be a way to identify, combined with network diagnostigs:
https://github.com/openthread/openthread/blob/main/src/cli/README.md#networkdiagnostic-get-addr-type-
"
So that at least gives us some pointers to where we could look.
I will keep digging for some way to do this.
Let me know if you find anything yourself as well.
Regards,
Sigurd Hellesvik
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