Skip to content

Commit 69eb385

Browse files
authored
Merge pull request #184 from husigeza/Coap_documentation
Move CoAp documentation to correct location
2 parents 42f3035 + ed08cfa commit 69eb385

File tree

2 files changed

+42
-21
lines changed

2 files changed

+42
-21
lines changed

config.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,12 +737,19 @@ theme = "doc-theme"
737737
parent = "firmwareapi@pycom@network"
738738
weight = 20
739739

740+
[[menu.main]]
741+
name = "CoAP"
742+
url = "/firmwareapi/pycom/network/coap/"
743+
identifier = "firmwareapi@pycom@network@coap"
744+
parent = "firmwareapi@pycom@network"
745+
weight = 20
746+
740747
[[menu.main]]
741748
name = "Bluetooth"
742749
url = "/firmwareapi/pycom/network/bluetooth/"
743750
identifier = "firmwareapi@pycom@network@bluetooth"
744751
parent = "firmwareapi@pycom@network"
745-
weight = 30
752+
weight = 40
746753

747754
[[menu.main]]
748755
name = "GATT"

firmwareapi/pycom/network/coap.md renamed to content/firmwareapi/pycom/network/coap.md

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
# COAP
2-
1+
---
2+
title: "CoAP"
3+
aliases:
4+
- firmwareapi/pycom/network/coap.html
5+
- firmwareapi/pycom/network/coap.md
6+
- chapter/firmwareapi/pycom/network/coap
7+
---
38
This module implements a CoAp Server and Client, it operates as both at the same time.
49

510
## Usage Example
@@ -97,30 +102,33 @@ Returns with the socket assigned to the given `address` and `port` during `Coap.
97102
#### Coap.add_resource(uri, *, media_type=-1, max_age=-1, value=0, etag=False)
98103

99104
Creates a resource object and adds it to the Coap Module to operate as a server.
105+
100106
* `uri` is the full path of the resource.
101107
* `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.
102108
* `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.
103109
* `value` is the default value of the resource. If not given it is initialized to decimal 0.
104110
* `etag` is a boolean argument to enable/disable entity tag calculation (Coap option: ETag). By default it is turned off.
105111

106112

107-
{% hint style="info" %}
113+
{{% hint style="info" %}}
108114
Media type argument should be one of the standard defined value which are available via Coap Module's constants.
109-
{% endhint %}
115+
{{% /hint %}}
110116

111-
{% hint style="info" %}
117+
{{% hint style="info" %}}
112118
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 %}}
114120

115121

116122
#### Coap.remove_resource(uri)
117123

118124
Removes the resource defined by `uri` argument.
125+
119126
* `uri` is the full path of the resource to be removed.
120127

121128
#### Coap.get_resource(uri)
122129

123130
Returns with the resource defined by `uri` argument.
131+
124132
* `uri` is the full path of the resource to be returned.
125133

126134
#### Coap.read()
@@ -130,16 +138,18 @@ Must be called when a packet is received on the socket assigned to the Coap Modu
130138
#### Coap.register_response_handler(callback)
131139

132140
Registers a callback function which will be called when a remote Coap Server responses to our request.
141+
133142
* `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
147+
* `payload` is the payload of the received message
139148

140149
#### Coap.send_request(uri_host, method, *, uri_port=5683, uri_path, content_format, payload, token, include_options=true)
141150

142151
Creates and sends a request to a Coap server.
152+
143153
* `uri_host` is the IP address of the server, included in the message as an "URI-HOST" option
144154
* `method` is the method to be sent to the server, can be: `Coap.REQUEST_GET`, `Coap.REQUEST_PUT`, `Coap.REQUEST_POST`, `Coap.REQUEST_DELETE`
145155
* `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.
160170
#### resource.add_attribute(name, value)
161171

162172
Adds a new attribute to the resource. Attributes are used to explain the resource during service discovery.
173+
163174
* `name` is the name of the resource.
164175
* `value` is the value of the resource.
165176

166-
{% hint style="info" %}
177+
{{% hint style="info" %}}
167178
During service discovery, GET request to ".well-know/core", the attributes are returned with the belonging values.
168179
E.g. using the "libcoap's" command line coap-client to fetch the resource from our server:
169180

170181
coap-client -m get coap://<Coap-Server's address>/.well-known/core
171-
</resource2>,</resource1>;ct=0;title=resource1
172182

173-
{% endhint %}
183+
< /resource2>,< /resource1>;ct=0;title=resource1
184+
185+
{{% /hint %}}
174186

175187
#### resource.value(value)
176188

177189
Updates or fetches the value of the resource.
190+
178191
* `value` is the value to update the current value with.
179192
If the method is called without parameter the current value is returned.
180193

181194
#### resource.callback(operation, enable)
182195
To enable or disable a specific operation (GET, PUT, POST, DELETE) on the resource.
196+
183197
* `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`
184198
* `enable` is boolean parameter to enable/disable the operations specified by `operation`
185199

186200

187-
{% hint style="info" %}
201+
{{% hint style="info" %}}
188202
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 %}}
190204

191-
{% hint style="info" %}
205+
{{% hint style="info" %}}
192206
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 %}}
194208

195-
{% hint style="danger" %}
209+
{{% hint style="danger" %}}
196210
Due to limitations of the underlying ESP-IDF/libcoap library, new resources cannot be added via PUT or POST requests.
197-
{% endhint %}
211+
{{% /hint %}}
198212

199213
## Constants
200214

0 commit comments

Comments
 (0)