You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*`address` is the address where the CoAp module handles communication when it is a Server. If not set, the module can be used as a CoAp Client only.
184
199
*`port` is the port where the CoAp Server listens. If not set, the default CoAp UDP port is 5683.
185
200
*`service_discovery` is a Boolean argument that enables/disables service discovery. If enabled, the CoAp Server will listen on the CoAp multicast address: 224.0.1.187. This is disabled by default.
201
+
*`dynamic_resources` is a Boolean argument that enables/disables new resource creation via PUT operations. This is disabled by default.
202
+
203
+
When `dynamic_resources` is TRUE new resources can be created via PUT reqeusts, if the resource with the given URI does not already exist.
204
+
The new resource is created with default properties (no mediatype, no Max-Age and no ETAG is enabled) and with default value received in the PUT request. On the new resource by default all operations (GET, PUT, POST and DELETE) are enabled.
186
205
187
206
## Methods:
188
207
@@ -239,6 +258,13 @@ Registers a callback function which will be called when a remote CoAp Server res
239
258
*`token` is the token field from the received message
240
259
*`payload` is the payload of the received message
241
260
261
+
#### Coap.register_new_resource_handler(callback)
262
+
263
+
Registers a callback function which will be called when a a new resource has been created via PUT operation.
264
+
265
+
*`callback` is the callback to be registered. It must have the following arguments:
266
+
*`resource` is the new resource which has been created
Creates a new CoAp Client Session which can be used to communicate with an external CoAp Server.
@@ -284,7 +310,7 @@ Returns with a list of elements showing internal information about this CoAP Cli
284
310
285
311
## Class CoapResource
286
312
287
-
The CoapResource class represents a resource in the scope of the CoAp module when acting as a server. A new resource can only be created with the `Coap.add_resource` function.
313
+
The CoapResource class represents a resource in the scope of the CoAp module when acting as a server.
288
314
289
315
#### Class methods
290
316
@@ -307,6 +333,25 @@ coap-client -m get coap://<Coap-Server's address>/.well-known/core
307
333
308
334
{{% /hint %}}
309
335
336
+
#### CoapResource.get_details()
337
+
338
+
Returns with the main details of this resource in a form of list:
339
+
*`Item 0:` is the URI of the resource.
340
+
*`Item 1:` is the mediatype (content format) configured for this resource. -1 means no mediatype is configured.
341
+
*`Item 2:` is the Max-Age configured for this resource. -1 means no Max-Age is configured.
342
+
*`Item 3:` is a boolean showing whether ETAG is enabled on this resource.
*`mediatype` is the mediatype (content format) os the resource. Value -1 means no mediatype is defined for this resource.
349
+
*`max_age` is max-age value to be used on the resource. Value -1 means no Max-Age is defined for this resource.
350
+
*`etag` is a Boolean which enables or disables ETAG on the resource.
351
+
352
+
This function leaves untouched any property of the resource not given as a parameter.
353
+
354
+
310
355
#### CoapResource.value(value)
311
356
312
357
Updates or fetches the value of the resource.
@@ -322,15 +367,15 @@ To enable or disable a specific operation (GET, PUT, POST, DELETE) on the resour
322
367
323
368
324
369
{{% hint style="info" %}}
325
-
During a GET request, only the first occurrence of an ETAG or Accept option is passed on and interpreted; others of the same type are dropped (if any).
370
+
During a GET request, only the first occurrence of an ETAG or Accept option is interpreted; others of the same type are dropped (if any).
326
371
{{% /hint %}}
327
372
328
373
{{% hint style="info" %}}
329
-
During a PUT request, only the first occurrence of an If-Match option is passed on and interpreted; others of the same type are dropped (if any).
374
+
During a PUT request, only the first occurrence of an If-Match and If-None-Match option is interpreted; others of the same type are dropped (if any).
330
375
{{% /hint %}}
331
376
332
377
{{% hint style="danger" %}}
333
-
Due to limitations of the underlying ESP-IDF/libcoap library, new resources cannot be added via PUT or POST requests.
378
+
Due to limitations of the underlying ESP-IDF/libcoap library, new resources cannot be added via POST request.
0 commit comments