Search code examples
getresourcesnumberspayloadcoap

How do you send a number when you answer a get request with coap


I've been reading the rfc 7252 for a while and I am probably blind but I can't find how can I send a simple number (integer or float) when you answer a get request for a ressource (for example the sensor /light, where do you write it in the packet.

I think it's in the payload, so I tried to send this packet : the option content-format text/plain, charset=utf-8, length 1 then I write 255(0xff) in the packet then I write 0x34 in the packet (payload part).

But obviously it's not working, first I don't think I should use this option (probably another one but I can't find the good one to send either integer or float number), I'm not sure though if I'm in the right way and not sure anymore of what I am doing tbh, so that's why I'm asking.

Thanks for help,

Good bye

EDIT : Here are more info : I'm using microcoap on arduino, using an ethernet cable between computer/arduino mega 2560. wireshark info


Solution

  • After reviewing your Wireshark trace and seeing the response in Copper I think I see the problem. When you say that the Content-format is text/plain you are saying that you are sending ASCII data across. You say you send [0xFF 0x34] in your post, but in the trace you are actually sending is [0xFF 0x33]. Copper is showing you exactly what you are sending: 0xFF doesn't resolve as ASCII here and 0x33 is the ASCII for 3, which is shown in the Wireshark trace and in your Copper output window. If you want to send 2 raw bytes of data that shouldn't be interpreted as text you want to set your Content-format to be application/octet-stream.