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
Creates a resource object and adds it to the Coap Module to operate as a server.
105
+
100
106
*`uri` is the full path of the resource.
101
107
*`media_type` is the media type (Coap option: Content-Format) of the resource. If not given, no defined media type is associated with the resource.
102
108
*`max_age` is the maximum time in seconds when the value of the resource is considered fresh (Coap option: Max-Age). If not given, no fresh time is associated with the resource.
103
109
*`value` is the default value of the resource. If not given it is initialized to decimal 0.
104
110
*`etag` is a boolean argument to enable/disable entity tag calculation (Coap option: ETag). By default it is turned off.
105
111
106
112
107
-
{% hint style="info" %}
113
+
{{% hint style="info" %}}
108
114
Media type argument should be one of the standard defined value which are available via Coap Module's constants.
109
-
{% endhint %}
115
+
{{% /hint %}}
110
116
111
-
{% hint style="info" %}
117
+
{{% hint style="info" %}}
112
118
Entity tag calculation is a simple counter increment between value 1-65535 with overflow but without value 0. Incremented each time the value of the resource is changed.
113
-
{% endhint %}
119
+
{{% /hint %}}
114
120
115
121
116
122
#### Coap.remove_resource(uri)
117
123
118
124
Removes the resource defined by `uri` argument.
125
+
119
126
*`uri` is the full path of the resource to be removed.
120
127
121
128
#### Coap.get_resource(uri)
122
129
123
130
Returns with the resource defined by `uri` argument.
131
+
124
132
*`uri` is the full path of the resource to be returned.
125
133
126
134
#### Coap.read()
@@ -130,16 +138,18 @@ Must be called when a packet is received on the socket assigned to the Coap Modu
130
138
#### Coap.register_response_handler(callback)
131
139
132
140
Registers a callback function which will be called when a remote Coap Server responses to our request.
141
+
133
142
*`callback` is the callback to be registered. It must have the following arguments:
134
-
*`code` is the response code from the received message
135
-
*`id_param` is the transaction ID of the received message. This can be used to match together requests and the response for it.
136
-
*`type_param` is the type flag from the received message
137
-
*`token` is the token field from the received message
138
-
*`payload` is the payload of the received message
143
+
*`code` is the response code from the received message
144
+
*`id_param` is the transaction ID of the received message. This can be used to match together requests and the response for it.
145
+
*`type_param` is the type flag from the received message
146
+
*`token` is the token field from the received message
*`uri_host` is the IP address of the server, included in the message as an "URI-HOST" option
144
154
*`method` is the method to be sent to the server, can be: `Coap.REQUEST_GET`, `Coap.REQUEST_PUT`, `Coap.REQUEST_POST`, `Coap.REQUEST_DELETE`
145
155
*`uri_port` is the port of the server, included in the message as an "URI-PORT" option, by default it is 5683
@@ -160,41 +170,45 @@ The following methods are defined in the scope of the `resource` class.
160
170
#### resource.add_attribute(name, value)
161
171
162
172
Adds a new attribute to the resource. Attributes are used to explain the resource during service discovery.
173
+
163
174
*`name` is the name of the resource.
164
175
*`value` is the value of the resource.
165
176
166
-
{% hint style="info" %}
177
+
{{% hint style="info" %}}
167
178
During service discovery, GET request to ".well-know/core", the attributes are returned with the belonging values.
168
179
E.g. using the "libcoap's" command line coap-client to fetch the resource from our server:
169
180
170
181
coap-client -m get coap://<Coap-Server's address>/.well-known/core
171
-
</resource2>,</resource1>;ct=0;title=resource1
172
182
173
-
{% endhint %}
183
+
< /resource2>,< /resource1>;ct=0;title=resource1
184
+
185
+
{{% /hint %}}
174
186
175
187
#### resource.value(value)
176
188
177
189
Updates or fetches the value of the resource.
190
+
178
191
*`value` is the value to update the current value with.
179
192
If the method is called without parameter the current value is returned.
180
193
181
194
#### resource.callback(operation, enable)
182
195
To enable or disable a specific operation (GET, PUT, POST, DELETE) on the resource.
196
+
183
197
*`operation` is the operation to enable/disable, can be ORED of the followings: `Coap.REQUEST_GET`, `Coap.REQUEST_PUT`, `Coap.REQUEST_POST`, `Coap.REQUEST_DELETE`
184
198
*`enable` is boolean parameter to enable/disable the operations specified by `operation`
185
199
186
200
187
-
{% hint style="info" %}
201
+
{{% hint style="info" %}}
188
202
During a GET request, only the first occurance of an ETAG or Accept option is parsed and interpreted, the others of the same type are dropped (if any).
189
-
{% endhint %}
203
+
{{% /hint %}}
190
204
191
-
{% hint style="info" %}
205
+
{{% hint style="info" %}}
192
206
During a PUT request, only the first occurance of an If-Match option is parsed and interpreted, the others of the same type are dropped (if any).
193
-
{% endhint %}
207
+
{{% /hint %}}
194
208
195
-
{% hint style="danger" %}
209
+
{{% hint style="danger" %}}
196
210
Due to limitations of the underlying ESP-IDF/libcoap library, new resources cannot be added via PUT or POST requests.
0 commit comments