automote / ESP-CoAP

This repo contains CoAP protocol for ESP-12E
http://thingtronics.com
GNU General Public License v3.0
72 stars 28 forks source link

How to get uri.path from observed packets arriving from 8266 CoAp Server? #22

Open pcbtborges opened 5 years ago

pcbtborges commented 5 years ago

Dear friend, I set an experiment to see the workings of CoAp and for that I used your code at Github.

I set a 8266 Coap Server running one /led resource The second is an ESP12 running CoAp Client and it is set to observe the resource /led in the 8266 CoAp Server.

When /led changes at the CoAp Server ( I am using a browser with CoAp for that) the ESP12 is notified. It works ok.

The problem is that, in case I am observing more than one resource at the server I must find a way to identify what resource is generating the packet when it arrives at the following function:

`// 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;

char t[packet.tokenlen + 1];
memcpy(t, packet.token, packet.tokenlen);
t[packet.tokenlen] = NULL;    

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

Serial.print("type: ");
Serial.print(packet.type);
Serial.print(" - code: ");
Serial.print(packet.code);
Serial.print(" - messageid: ");
Serial.print(packet.messageid);    
Serial.print(" - optionnum: ");
Serial.print(packet.optionnum); 
Serial.print(" - token: ");
Serial.println(t);     

Serial.println(p);

}`

I tried to print all variables I could find but had no success with uri.path.

So, my question is: How to get the "/led" resource name so I can patch the payload value to the correct variable?

Thanks in advance for your time. And Congrats for the excellent work!

Paulo Borges