-->
Page 1 of 1

CoAp Server. How to get resource name from observed resource

PostPosted: Thu Jul 11, 2019 2:27 pm
by Paulo Borges
I am trying CoAp and set one 8266 as CoAp Server and a second one as Client.
Server ir running a resource /led.
Client8266 is observing the resource /led.
When /led changes state at the Coap Server, it sends packet to Client informing about the change.
Received payload at the Client can be 1 or 0 and it works fine.

Packets received are processed by the function below:

Code: Select all// coap client response callback
void callback_response(coapPacket &packet, IPAddress ip, int port) {
    char p[packet.payloadlen + 1];
    memcpy(p, packet.payload, packet.payloadlen);
    p[packet.payloadlen] = NULL;

    //response from coap server
    if(packet.type==3 && packet.code==0){
      Serial.println("ping ok");
    }
    Serial.println(p);
}


Question:

How can I identify to what resource the packet refers to?
So far I found no way to know it comes from /led

Thanks in advance.
Paulo