Skip to content
simen edited this page May 11, 2017 · 22 revisions

Overview


About freebird-rpc

This module is a transportation with WebSocket protocol, which is used by the RPC interface of freebird framework. It provides methods to create RPC client and RPC server for real-time remote communications between freebird and client apps.

The RPC server should be registered to freebird framework to be able to transmit freebird messages to RPC client (e.g., the web browser). And the RPC client is for webapp to be able to communicate with freebird.


Why Subsystems?

The freebird framework has net, dev, and gad subsystems responsible for network, device, and gadget management, respectively.

In short, a network is formed with many devices, and each device may have some gadgets on it. A gadget is the real application in a manchine network.

The concept of net, dev, and gad subsystems in freebird framework well separates the machine management and application management from each other. This brings developers a more clear, convenient and flexible way in building up a IoT machine network.


Explaining the Concept

Let's take a wifi weather station in a machine network for example.

  • The weather station is made up of temperature, humidity, and pm2.5 sensors, where each sensor is a gadget living on the WiFi-connected device.
  • A device, such as Arduino(wifi-connected), ESP8266, MT7688, RaspberryPi or Beaglebone, is the carrier of applications(gadgets).
  • Now we know, this weather station has 3 gadgets on it, but only has a single device in it.

Here is another example, we have a bluetooth low-energy (BLE) light switch in the network.

  • This is a simple one-device-with-one-gadget machine.
  • Here we can say "There is only one gadget - a light switch - implemented on a TI CC2540 BLE SoC device."


Installtion and Usage



Installation

$ npm install freebird-rpc --save



Usage

freebird-rpc exports its functionalities with two methods createServer() and createClient() to create a RPC server and a client, respectively.

var fbRpc = require('freebird-rpc'),
    http = require('http');

var httpServer = http.createServer();
httpServer.listen(3000);

var rpcServer = fbRpc.createServer(httpServer);

// register to the freebird
freebird.addTransport(rpcServer, function (err) {
    if (err)
        console.log(err);
});
  • Create a RPC client (e.g., webapps or mobile apps)
var fbRpc = require('freebird-rpc');

var rpcClient = fbRpc.createClient('ws://192.168.1.108:3000');

rpcClient.on('open', function () {
    // channel established
});

rpcClient.on('close', function () {
    // channel closed
});

rpcClient.on('ind', function (msg) {
    // indication sent from the freebird server
});