Incorrect GET response after POST

Hello, I’m in the process of reviving the golioth-rs repo and rebasing it on Embassy and nrf-modem for async support in Rust :slight_smile: I’ve run into a small problem and I’m not sure where to go from here. I’m using CoAP and DTLS.

I’m using an atomic u16 type that is incremented and used for the message header id anytime I make a CoAP request, just like the original repo. If I make a GET request I get a good response:

60 45 00 00 48 C2 2E 52 8D 07 04 8E 9D 80 FF 7B 22 73 74 61 74 61 74 61 74 65 22 3A 74 72 75 65 7D

which decodes into

UDP

Message:
{
  "type": "Acknowledgement",
  "code": "Content",
  "id": 0,
  "token": 0,
  "options": [
    "ETag(etag=C2 2E 52 8D 07 04 8E 9D",
    "Content-Format: text/plain; charset=utf-8"
  ]
}

Payload:
{"state":true}

If I attempt to GET after I perform a POST, I get this instead

60 44 00 00 48 00 00 00 00 00 00 CA 0C 80 FF 4F 4B

which decodes to

Message:
{
  "type": "Acknowledgement",
  "code": "Changed",
  "id": 0,
  "token": 0,
  "options": [
    "ETag(etag=00 00 00 00 00 00 CA 0C",
    "Content-Format: text/plain; charset=utf-8"
  ]
}

Payload:
OK

It seems that I am picking up a response from the previous POST? I’m not a networking guru, so I’m a little unsure of what is going on, should I use PUT instead of POST or should I wait a certain amount of time before doing a GET after PUT/POST?

Ha, I figured it out. I was right, the response is from the previous POST and not the GET (the id is the tale tell sign). I solved this, by making POSTs Nonconfirmable types so they don’t interfere with the responses of GETs.

Successful GET after LightDB Stream and State POSTs:

UDP

Message:
{
  "type": "Acknowledgement",
  "code": "Content",
  "id": 2,
  "token": 0,
  "options": [
    "ETag(etag=C2 2E 52 8D 07 04 8E 9D",
    "Content-Format: text/plain; charset=utf-8"
  ]
}

Payload:
{"state":true}
2 Likes