Skip to content
simen edited this page Mar 7, 2017 · 18 revisions

1. Overview

freebird-netcore-mqtt is the network controller (netcore) with managment facilities ready for freebird IoT framework.


2. Installation

$ npm install freebird-netcore-mqtt --save


3. Basic Usage

  • To use this netcore, simply register it when creating the freebird server:
var Freebird = require('freebird'),
    mqttCore = require('freeebird-netcore-mqtt')();

// Create the freebird server and register the freeebird-netcore-mqtt to it
var freebird = new Freebird([ mqttCore ]);

// Simply start the freebird server
freebird.start(function (err) {
    console.log(mqttCore.getName());    // 'freebird-netcore-mqtt'

    // Allow your mqtt peripheral machines to join the network within 180 seconds
    freebird.permitJoin(180);
});

// That's it!

4. Table of APIs

Netcore provides you with APIs summarized in the following table, please go to Netcore APIs for their usage. The only thing you should know here is the createMqttCore() API that exported by the freebird-netcore-mqtt module.




createMqttCore([name][, settings])

The freebird-netcore-mqtt module exports a function createMqttCore() for you to create a MQTT netcore with a given name (optional) and the broker settings (optional).

Arguments

  1. name (String): The netcore name. A default name 'freebird-netcore-mqtt' will be used if not given.

  2. settings (Object): Optional settings for the netcore.

    Property Type Description
    broker Object Broker settings in shape of { port, backend }, where backend is a pubsubsettings object given in Mosca wiki page. You can set up your own MQTT backend, like mongoDB, Redis, Mosquitto, or RabbitMQ, through this option.
    account Object Set default account with a { username, password } object, where username and password are strings. Default is null to accept all incoming Clients.
    reqTimeout Number Number of milliseconds, a global timeout for all requests.
    dbPath String Set database file path, default is __dirname + '/database/mqtt.db'.

Returns

  • (Object): netcore

Example

  • Create a netcore and name it
var createMqttCore= require('freeebird-netcore-mqtt');
var mqttCore = createMqttCore('my_mqtt_core');
  • Create a netcore that will start on a specified port
var createMqttCore= require('freeebird-netcore-mqtt');
var mqttCore = createMqttCore('my_mqtt_core', {
    broker: {
        port: 9000
    }
});



  • Basic Methods
Medthod Description
getName Get name of this netcore.
isEnabled To see if this netcore is enabled.
isRegistered To see if this netcore is registered to freebird framework.
isJoinable To see if this netcore is currently allowing devices to join the network.
enable Enable this netcore.
disable Disable this netcore.
dump Dump information about the netcore.



  • Network Management
Medthod Description
start Start the network. To allow devices to join the network, use permitJoin().
stop Stop the network. All functions are disabled.
reset Reset the netcore. Soft reset just restart the netcore, and hard reset will clear the blacklist.
permitJoin Allow or disallow devices to join the network.
remove Remove a remote device from the network.
ban Ban a device from the network. Banned device can never join the network unless you unban it.
unban Unban a device.
ping Ping a remote device.
maintain Maintain all remote devices managed by the netcore.
getTraffic Get traffic records.
resetTraffic Reset record of the traffic.
getBlacklist Get blacklist of the banned devices. Use ban() to put a device into blacklist.
clearBlacklist Clear the blacklist. Use unban() to release a device from blacklist.
isBlacklisted To see if a device is banned.