
What is LWMQN
Lightweight Message Queuing Network (LwMQN) is an open source project that follows part of OMA LwM2M v1.0 specification to meet the minimum requirements of machine network management.
Server-side and Client-side Libraries:
- LwMQN project provides you with this machine-side @lwmqn/qnode library and a server-side @lwmqn/shepherd library to build your machine network with JavaScript and node.js easily.
Features
- Communication based on MQTT protocol and mqtt.js client.
- Hierarchical Smart Object data model (IPSO), which leads to a comprehensive and consistent way in describing real-world gadgets.
- LWM2M-like interfaces for Client/Server interaction.
- Auto handles many REQ/RSP things for you. All you have to do is to plan your Resources well.
Acronyms and Abbreviations
- Server: LWMQN server
- Client or Client Device: LWMQN client, which is a machine node in the network
- Qnode: Class exposed by
require('@lwmqn/qnode')
- SmartObject: Class exposed by
require('@lwmqn/smartobject')
- qnode: Instance of Qnode class
- so: Instance of SmartObject class
Installation
Currently Node.js 8.x LTS or higher is required.
$ npm install @lwmqn/qnode
$ npm install @lwmqn/smartobject
Basic Usage
Here is a quick example, with two humidity sensors and one custom object, which shows how to use @lwmqn/qnode and smartobject on your client machine.
var Qnode = require('@lwmqn/qnode')
var SmartObject = require('@lwmqn/smartobject')
var so = new SmartObject()
so.init('humidity', 0, {
sensorValue: 20,
units: 'percent'
})
so.init('humidity', 1, {
sensorValue: 16,
units: 'percent'
});
so.init('myObject', 0, {
myResrc1: 20,
myResrc2: 'hello world!'
})
var qnode = new Qnode('my_foo_client_id', so);
qnode.on('ready', function () {
})
qnode.on('registered', function () {
})
qnode.on('login', function () {
})
qnode.connect('mqtt://192.168.0.2');
The following example shows how to operate upon this qnode at server-side (please go to mqtt-shepherd document for details):
var qnode = qserver.find('my_foo_client_id');
if (qnode) {
qnode.readReq('humidity/0/sensorValue', function (err, rsp) {
if (!err) console.log(rsp);
})
qnode.readReq('myObject/0/myResrc2', function (err, rsp) {
if (!err) console.log(rsp);
});
}
Documentation
License
Licensed under MIT.