Prototype of an IoT Agent accepting COAP requests and redirecting to NGSI consumer
npm install lightweightm2m-iotagentOMA Lightweight M2M IoT Agent
==================
* Overview
* Prerequisites
* Installation
* Usage
* Configuration
* Packaging
* Testing
For more information on what an IoT Agent is or how it should work, please check the documentation on the Node IoT Agent Library.
For more information on OMA Lightweight M2M you can check the Node.js OMA Lightweight M2M library we are using.
If you just want to start using the agent, jump to the Quick Start Guide.
lwm2m configuration section in the config.js config file, a url prefix has to be defined. Whenever a registration arrives to an url with that prefix, the device will be assigned the corresponding type.In order to accomplish this task, the agent supports:
* An aditional property lwm2mResourceMapping that lets the user configure names for to each of the particular resources exposed by a device Type
* Two optional configuration file, omaRegistry.json containing the automatic mappings that will be applied in case there are no custom mappings.
Custom mappings defined by the user in the config.js file or by preprovisioning devices take precedence over any other available mapping.
The OMA Registry information is read from two files: omaRegistryMap.json and omaRegistryInverseMap.json. This two files can be generated with the last information in the OMA Registry with the command bin/downloadOmaRegistry.js. Notice that the generated files do not have the same name than the original ones (so the result can be double-checked before changing them). In order to use the freshly downloaded ones, just remove the former and rename the latter.
NOTE: the current version of Node.js, 0.12.x has not been tested with the Agent, so we suggest to download and use the previous version (that process can be eased with utilities as n or nvm).
npm install
`
This will download the dependencies for the project, and let it ready to the execution.Using the RPM
To see how to generate the RPM, follow the instructions in Packaging.To install the RPM, use the YUM tool:
`
yum localinstall --nogpg
` Usage
Github installation
In order to execute the IOTAgent, just issue the following command from the root folder of the cloned project:
`
bin/lwm2mAgent.js [config file]
`
The optional name of a config file is optional and described in the following section.RPM installation
The RPM installs a linux service that can be managed with the typical instructions:
`
service iotagent-lwm2m startservice iotagent-lwm2m status
service iotagent-lwm2m stop
`In this mode, the log file is written in
/var/log/iotagent-lwm2m/iotagent-lwm2m.log. Configuration
There are two ways to provide the IOT Agent with a configuration set: passing the name of a config file (related to the root folder of the project) or customize the example config.js in the root. The configuration file is divided in two sections: one standard section for the NGSI North bound
ngsi, and another one for the specific Lightweight M2M South bound, lwm2m. The former follows the same format described for the Node.js IOT Agent Framework, described here. The latter configures the Lightweight M2M library used for communicating with the devices, as described here (server section).These are the specific LWM2M parameters that can be configured for the agent:
* logLevel: level of logs for the IOTAgent specific information. E.g.: 'DEBUG'.
* port: UDP port where the IOTAgent will be listening. E.g.: 60001.
* defaultType: for the cases when no type can be assigned to a device (no preprovision or path asignation of type), this type will be assigned by default. E.g.: 'Device'
* types: for IOTAgents with multiple southbound paths, this attribute maps attribute types (defined either in the configuration file or by using the Device Configuration API) to southbound interfaces. E.g.:
`
{
name: 'Light',
url: '/light'
},
{
name: 'Pressure',
url: '/pres'
},
{
name: 'Arduino',
url: '/arduino'
}
`
Packaging
The only package type allowed is RPM. In order to execute the packaging scripts, the RPM Build Tools must be available
in the system.From the root folder of the project, create the RPM with the following commands:
`
cd rpm
./create-rpm.sh
`
Where is the version (x.y.z) you want the package to have and is an increasing
number dependent un previous installations. Testing
The IoT Agent comes with a test suite to check the main functionalities. In order to execute the test suite you must have the Grunt client installed. You can install it using the following command (you will need root permissions):
`
npm install -g grunt-cli
`
Once the client is installed and the dependencies are downloaded, you can execute the tests using:
`
grunt
``NOTE: This are end to end tests, so they execute against real instances of the components (so make sure you have a real Context Broker configured in the config.js). Be aware that the tests clean the databases before and after they have been executed so DO NOT EXECUTE THIS TESTS ON PRODUCTION MACHINES.