Skip to content
This repository was archived by the owner on Apr 24, 2019. It is now read-only.

Commit 47a2eea

Browse files
authored
Merge pull request #252 from ARMmbed/porting-guide-doc
Updating docs related with reconnection logic and configuration.
2 parents 91310af + 353686b commit 47a2eea

File tree

2 files changed

+102
-6
lines changed

2 files changed

+102
-6
lines changed

docs/Introduction.md

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ _interface->set_random_number_callback(&get_random_number);
6464

6565
mbed Client provides an API to add your own entropy source into the underlying SSL library. There is a default entropy source provided by mbed Client. It uses PRNG seeded with RTC for the security but some platforms do not have RTC, and for some, this level of security may not be strong enough.
6666

67-
Now, an application can pass its own entropy source to mbed Client as function pointer callback through an API, `set_entropy_callback(entropy_cb callback)`.
67+
Now, an application can pass its own entropy source to mbed Client as function pointer callback through an API `set_entropy_callback(entropy_cb callback)`.
6868

6969
Here is an example on how you can use it from an application:
7070

@@ -101,7 +101,18 @@ The maximum single UDP message size that mbed Client can receive is 1152 bytes.
101101

102102
For transferring larger amounts of data, the Blockwise feature must be deployed. When using this feature, mbed Client can handle messages up to 64KB. This feature is disabled by default.
103103

104-
To enable the Blockwise feature, you need to create a `config.json` file in the application level.
104+
For mbed OS, to enable Blockwise feature , create a `mbed_app.json` file in the application level and overwrite Blockwise value as described below:
105+
106+
*Example:*
107+
```
108+
"target_overrides": {
109+
"*": {
110+
"mbed-client.sn-coap-max-blockwise-payload-size": 1024
111+
}
112+
113+
```
114+
115+
For yotta based builds, to enable the Blockwise feature, you need to create a `config.json` file in the application level.
105116

106117
*Example:*
107118
```
@@ -115,9 +126,19 @@ Acceptable values for the `coap_max_blockwise_payload_size` flag are:
115126

116127
### CoAP message deduplication
117128

118-
Message duplication is disabled by default. More information about deduplication in the [CoAP specification](https://tools.ietf.org/html/rfc7252#page-24).
129+
By default, message deduplication is disabled. More information about deduplication in the [CoAP specification](https://tools.ietf.org/html/rfc7252#page-24).
130+
131+
For mbed OS, to enable message deduplication, create a `mbed_app.json` file in the application level and overwrite the deduplication value as described below:
132+
133+
*Example:*
134+
```
135+
"target_overrides": {
136+
"*": {
137+
"mbed-client.sn-coap-duplication-max-msgs-count": 1
138+
}
119139
120-
To enable message deduplication, you need to create a `config.json` file in the application level.
140+
```
141+
For yotta based builds, to enable message deduplication, you need to create a `config.json` file in the application level.
121142

122143
*Example:*
123144
```
@@ -127,6 +148,53 @@ To enable message deduplication, you need to create a `config.json` file in the
127148
```
128149
Recommended values for the `coap_duplication_max_msgs_count` flag are 0 to 6. Value 0 means that the feature is not used. It is not recommended to use higher value than 6, because it increases the memory consumption.
129150

151+
### Reconnectivity
152+
153+
Apart from standard CoAP features, mbed Client also handles reconnectivity logic on behalf of applications, thereby aiming to provide seamless connectivity experience and recovery from temporary network hiccups or service side disruptions.
154+
155+
The reconnection logic handles the following:
156+
157+
- Reconnection towards mDS; establishing the network connection and re-registration to mDS.
158+
- CoAP message resending logic. More information about resending in [CoAP specification](https://tools.ietf.org/html/rfc7252#section-4.8).
159+
160+
There are two parameters in the reconnection logic, both configurable by the application:
161+
162+
- Reconnection Retry
163+
- Reconnection Time Interval (in seconds)
164+
165+
mbed Client tries to establish a successful connection to the server by incrementing the reconnection trials every time there is a failed connection attempt.
166+
167+
The logic of the `Reconnection Timeout` is `Reconnection Retry count * Reconnection Time Interval` , where `Reconnection Retry count` is incremented by 1 with every failed reconnection attempt.
168+
169+
mbed Client continues to attempt a reconnection until `Reconnection Retry count` reaches the defined value (either by the application or the default value set in Client).
170+
171+
If mbed Client still cannot establish a connection and the set `Reconnection Retry count` is reached, it returns an error through a callback with an appropriate error code defining the reason for failed connection.
172+
173+
There are a few exceptions to the reconnection logic though. If mbed Client sends registration data that is rejected by the server, the client returns an error and does not attempt a reconnection as the server has rejected the data from the client. A typical example of such case would be passing a non-matching endpoint name or domain name against the client certificates.
174+
175+
Applications can define their own parameters for the reconnection logic.
176+
177+
For mbed OS, to overwrite the reconnection retry count and reconnection time interval, create a `mbed_app.json` file in the application level and overwrite the values as described below:
178+
179+
*Example:*
180+
```
181+
"target_overrides": {
182+
"*": {
183+
"mbed-client.reconnection-count": 3,
184+
"mbed-client.reconnection-interval": 5,
185+
}
186+
187+
```
188+
For yotta based builds, to overwrite the reconnection retry count and reconnection time interval, you need to create a `config.json` file in the application level.
189+
190+
*Example:*
191+
```
192+
{
193+
"reconnection_count": 3,
194+
"reconnection_interval": 5
195+
}
196+
```
197+
130198
## How to use the API
131199
More information on how to use the API effectively to create and configure Objects, Object Instances and Resources, can be found [here](Howto.md).
132200

docs/dev_man_serv_enable.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ The Client API allows setting values to Resources, an array of Resource Instance
6767

6868
The **Write** operation is used to overwrite the value of a Resource, an array of Resource Instances or multiple Resources from an Object Instance.
6969

70-
Whenever there is a valid `PUT` operation for any of the resources, the application will receive a callback:
70+
Whenever there is a valid `PUT` operation for any of the resources, the application will receive a callback:
7171

7272
```
7373
void value_updated(M2MBase *base, M2MBase::BaseType type)
@@ -119,6 +119,34 @@ void value_updated(M2MBase *base, M2MBase::BaseType type) {
119119
}
120120
}
121121
```
122+
By default, callbacks are handled in the `value_updated()` function but the application can also define a callback function for an individual resource.
123+
124+
Check the code snippet below for usage.
125+
126+
```
127+
static void value_updated_global(const char *name) {
128+
if(name) {
129+
...
130+
}
131+
}
132+
133+
void M2MLWClient::value_updated_function(const char* name) {
134+
if (name) {
135+
...
136+
}
137+
}
138+
139+
M2MResource* res = inst->create_dynamic_resource("D", "ResourceTest", true);
140+
char buffer[20];
141+
int size = sprintf(buffer,"%d",_value);
142+
res->set_operation(M2MBase::GET_PUT_POST_DELETE_ALLOWED);
143+
res->set_value((const uint8_t*)buffer, (const uint32_t)size);
144+
res->set_value_updated_function(value_updated_callback(this,&MbedClient::value_updated_function));
145+
/* Overloaded function can be used If callback function is not in class scope.
146+
res2->set_value_updated_function(value_updated_callback2(&value_updated_global));
147+
*/
148+
149+
```
122150

123151
## The Write Attributes operation
124152

@@ -182,7 +210,7 @@ if(_object) {
182210
(const uint32_t)size);
183211
res->set_execute_function(execute_callback(this,&M2MLWClient::execute_function));
184212
/* Overloaded function can be used If callback function is not in class scope.
185-
res->set_execute_function(&execute_function_2);
213+
res->set_execute_function(execute_callback_2(&execute_function_2));
186214
*/
187215
```
188216

0 commit comments

Comments
 (0)