Skip to content

Commit ae5011b

Browse files
committed
FIX Client configuration is fixed in the config file
1 parent 7d73c95 commit ae5011b

6 files changed

Lines changed: 28 additions & 1 deletion

File tree

CHANGES_NEXT_RELEASE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
- Retry connection of the client if there is any error.
22
- Capture Coap Router errors.
3+
- Client object of the library can't be configured when used as a library (#35).

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ Execute a read operation for the selected resource, identified following the LWT
284284
285285
### Client features
286286
287+
#### Configuration
288+
The LWM2M Client library has to be configured before any interaction with the remote LWM2M server. This configuration is done through the use of the `init()` function.
289+
This function takes a configuration object (can be the same one passed to the server), that has a `client` attribute with the configuraiton for the client (as described
290+
in the configuration section). Failing to do so may lead to unexpected results.
291+
287292
#### Registration
288293
Before making any interaction with a Lightweight M2M server, a client must register to it. This registration can be done with the following function:
289294
```

lib/lwm2m-client.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var objRegistry = require('./services/client/objectRegistry'),
3232
coapRouter = require('./services/coapRouter'),
3333
Readable = require('stream').Readable,
3434
logger = require('logops'),
35-
config = require('../config'),
35+
config,
3636
context = {
3737
op: 'LWM2MLib.Client'
3838
};
@@ -316,6 +316,20 @@ function unregister(deviceInformation, callback) {
316316
req.end();
317317
}
318318

319+
/**
320+
* Sets the configuration the client module will use in its interactions.
321+
*
322+
* @param {Object} newConfig Configuration object.
323+
*/
324+
function init(newConfig, callback) {
325+
config = newConfig;
326+
327+
if (callback) {
328+
callback();
329+
}
330+
}
331+
332+
exports.init = init;
319333
exports.registry = objRegistry;
320334
exports.register = register;
321335
exports.unregister = unregister;

test/unit/client/client-device-managment-test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ describe('Client-side device management', function() {
4343
} else {
4444
localhost = '127.0.0.1';
4545
}
46+
47+
lwm2mClient.init(config);
48+
4649
lwm2mClient.registry.reset(function() {
4750
memoryRegistry.clean(function () {
4851
lwm2mServer.start(config.server, function (error, srvInfo) {

test/unit/client/client-information-management-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ describe('Client-side information management', function() {
4747
localhost = '127.0.0.1';
4848
}
4949

50+
lwm2mClient.init(config);
51+
5052
lwm2mServer.start(config.server, function (error, srvInfo) {
5153
testInfo.serverInfo = srvInfo;
5254

test/unit/client/client-registration-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ describe('Client-initiated registration', function() {
4141
localhost = '127.0.0.1';
4242
}
4343

44+
lwm2mClient.init(config);
45+
4446
lwm2mClient.registry.reset(function() {
4547
memoryRegistry.clean(function () {
4648
lwm2mServer.start(config.server, function (error, srvInfo) {

0 commit comments

Comments
 (0)