OMA Lightweight M2M IoT Agent: User and Development Guide
The Lightweight M2M IoT Agent is a standard FIWARE IoT Agent that implements the bridge of the OMA Lightweight M2M protocol with the internal protocol for the FIWARE components (OMA NGSI). This IoT Agent is based in the public Node.js IoT Agent Library, where more information can be found about what the IoT Agents are and their different APIs.
This project has, then, two APIs:
- The API for traffic south of the IoT Agent (LWM2M): information about it can be found in the OMA Lightweight M2M official page. Information about the subset of Lightweight M2M already supported can be found in the LWM2M Library for Node.js we are using.
- The North Port Administration API: all the IoT Agents share a single Administration API, and it can be found in the Node.JS IoT Agent Library Documentation.
- The API for traffic north of the IoT Agent (NGSI): information about the North Port NGSI mapping can be obtained in the same Node.JS IoT Agent Library documentation.
You will find examples and more detailed information in the Getting Started howtos below.
This document links a set of howtos oriented to give a quick step-by-step example on how to use the agent with different types of configurations. It's important to remark that those configuration options are not mutually exclusive: an IoT Agent can have some device preprovisioned, some configuration groups defined and some static configurations also, each for different types of devices.
Some of the guides will share the use of a faked device type called
Robot with the following characteristics:
- be part of the service
- have an active attribute called
number, mapped to the LWM2M resource ID /7392/0/1.
- have a passive attribute called
string, mapped to the LWM2M resource ID /7392/0/2.
- have a command attribute called
location, mapped to the LWM2M resource ID /7392/0/3.
Some guides will show the use of the automatic OMA Registry mapping, using a faked device of type 'WeatherBaloon', with the following characteristics:
- be part of the service
- a passive attribute with resource ID /6/0/0 (Position: Longitude).
- a passive attribute with resource ID /6/0/1 (Position: Latitude).
- a passive attribute with resource ID /3303/0/0 (Temperature Sensor).
- an active attribute with resource ID /3312/0/0 (Power Control).
Each guide is presented with a brief explanation about its contents:
- Device Provisioning Guide: this guide shows how to configure, launch and use an IoT Agent, provisioning each device before sending its measures.
- Configuration Provisioning Guide: this guide shows how to configure a group of devices for being autoprovisioned when they register in the agent.
- Static Configuration Guide: this guide shows how to configure static routes that map incoming devices to different statically configured types.
The IoT Agent comes with a test suite to check the main functionalities. You can execute the tests using:
This will execute the functional tests.
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.
It must be also noted that although the lightweightM2M-iotagent works with MongoDB replica sets, the unit testing suite and its scripts require using a single MongoDB instance.
Being an Open Source project, everyone can contribute, provided that it respect the following points:
- Before contributing any code, the author must make sure all the tests work (see below how to launch the tests).
- Developed code must adhere to the syntax guidelines enforced by the linters.
- Code must be developed following the branching model and change log policies defined below.
- For any new feature added, unit tests must be provided, following the example of the ones already created.
In order to start contributing:
- Fork this repository clicking on the "Fork" button on the upper-right area of the page.
- Clone your just forked repository:
git clone https://github.com/your-github-username/lightweightm2m-iotagent.git
- Add the main lightweightm2m-iotagent repository as a remote to your forked repository (use any name for your remote repository, it does not have to be lightweightm2m-iotagent, although we will use it in the next steps):
git remote add lightweightm2m-iotagent https://github.com/telefonicaid/lightweightm2m-iotagent.git
Before starting contributing, remember to synchronize the
master branch in your forked repository with the
branch in the main lightweightm2m-iotagent repository, by following this steps
- Change to your local
masterbranch (in case you are not in it already):
git checkout master
- Fetch the remote changes:
git fetch lightweightm2m-iotagent
- Merge them:
git rebase lightweightm2m-iotagent/master
Contributions following this guidelines will be added to the
master branch, and released in the next version. The
release process is explaind in the Releasing section below.
In order to start developing a new feature or refactoring, a new branch should be created with name
This branch must be created from the current version of the
master branch. Once the new functionality has been
completed, a Pull Request will be created from the feature branch to
master. Remember to check both the linters and
the tests before creating the Pull Request.
Bugfixes work the same way as other tasks, with the exception of the branch name, that should be called
In order to contribute to the repository, these same scheme should be replicated in the forked repositories, so the new
features or fixes should all come from the current version of
master and end up in
bug/* branches are temporary, and should be removed once they have been merged.
There is another set of branches called
release/<versionNumber>, one for each version of the product. This branches
point to each of the released versions of the project, they are permanent and they are created with each release.
The project contains a version changelog, called CHANGES_NEXT_RELEASE, that can be found in the root of the project.
Whenever a new feature or bug fix is going to be merged with
master, a new entry should be added to this changelog.
The new entry should contain the reference number of the issue it is solving (if any).
When a new version is released, the change log is cleared, and remains fixed in the last commit of that version. The content of the change log is also moved to the release description in the GitHub release.
The process of making a release consists of the following steps:
- Create a new task branch changing the development version number in the package.json (with a sufix
-next), to the new target version (without any sufix), and PR into
- Create a tag from the last version of
masternamed with the version number and push it to the repository.
- Create the release in Github, from the created tag. In the description, add the contents of the change log.
- Create a release branch from the last version of
masternamed with the version number.
- Create a new task for preparing the next release, adding the sufix
-nextto the current version number (to signal this as the development version).
Its important to remark that this component's tests are end-to-end tests, that have some software requirements to be run. This requirements are the following:
- An instance of MongoDB running in
- An instance of Orion Context Broker running in the location configured in
testConfig.js(defaults to the alias
oriondb). This instance has to have the 1026 and 27017 open for connections coming from the tests.
The project is managed using npm.
For a list of available task, type
The following sections show the available options in detail.
The test environment is preconfigured to run BDD testing style.
Module mocking during testing can be done with proxyquire
To run tests, type
Uses provided .jshintrc flag file. To check source code style, type
npm run lint
To check consistency of the Markdown markup, type
npm run lint:md
Uses the provided
.textlintrc flag file. To check for spelling and grammar errors, dead links and keyword consistency,
npm run lint:text
Support for continuous testing by modifying a src file or a test. For continuous testing, type
npm run test:watch
If you want to continuously check also source code style, use instead:
npm run watch
Analizes the code coverage of your tests.
To generate an HTML coverage report under
site/coverage/ and to print out a summary, type
# Use git-bash on Windows npm run test:coverage
coverage folders, and
package-lock.json file so that a fresh copy of the project is
# Use git-bash on Windows npm run clean
Runs the prettier code formatter to ensure consistent code style (whitespacing, parameter placement and breakup of long lines etc.) within the codebase.
# Use git-bash on Windows npm run prettier
To ensure consistent Markdown formatting run the following:
# Use git-bash on Windows npm run prettier:text