hirotakaster / CoAP-simple-library

Other
111 stars 48 forks source link

Add Query Support #42

Closed YelloooBlue closed 5 months ago

YelloooBlue commented 5 months ago

When using this library, I have the same problem #37 I tried to make a few small modifications and it worked fine.

Before I added query support, queries were parsed as part of URI_PATH

coap.put(IPAddress(10, 0, 1, 1), 5683,"room/lights?n=bed&s=on","hello");

the Option will be resolved as

Option_URI_PATH : room
Option_URI_PATH : lights?n=bed&s=on

Based on the position of '/','?' and '&' characters, the path and query are separated

Option_URI_PATH : room
Option_URI_PATH : lights
Option_URI_QUERY : n=bed
Option_URI_QUERY : s=on

It supports the following cases:

  1. No URI_PATH parameter (root path)
  2. No URI_QUERY parameter
  3. Only URI_PATH without URI_QUERY.

The original functions are not affected. Thanks.

hirotakaster commented 5 months ago

@YelloooBlue Thank you for your PR. I will test now.