Code Monkey home page Code Monkey logo

kuzzle-freeboard-plugin's Introduction

Kuzzle freeboard plugin

Freeboard plugin to help integrate data from a Kuzzle Server to your Freeboard IoT Dashboard

Kuzzle Datasource

Kuzzle Datasource freeboard plugin allow to take advantage of Kuzzle Realtime capabilities to monitor any realtime parametter of your Kuzzle based IoT application.

For now, Kuzzle Freeboard Datasource plugin is limited to monitoring document when they are created, but you could easily adapt it to monitor document when they are updated, deleted, or published for pure realtime documents (documents that are not stored).

This document focuses on using the plugin with freeboard running locally, using the development version: freeboard/index-dev.html. You can get it from Freeboard/freeboard. It should take little effort to get the plugin available for online version at freebord.io.

Enable Kuzzle Datasource Plugin

First you have to make Kuzzle JS sdk available to freeboard plugins. One way to do this, is to kuzzle-sdk it to freeboard depndencies using npm.

In freeboard folder enter the following command:

$ npm install kuzzle-sdk

Then modify freeboard/index-dev.html file to add loading of Kuzzle JS SDK, and Kuzzle DataSource plugin.

    <script type="text/javascript">
        head.js("lib/js/thirdparty/knockout.js",
                "lib/js/thirdparty/jquery.js",
                "plugins/freeboard/freeboard.widgets.js",
                .
                .
                .
                "examples/plugin_example.js",

                // Make Kuzzle() available
                "node_modules/kuzzle-sdk/dist/kuzzle.js",
                // Load Kuzzle Datasource plugin
                "path-to/..../kuzzle-freeboard-plugin/kuzzle_datasource.js",

                // *** Load more plugins here ***
                function(){
                    $(function()
                    .
                    .

You can now check that Kuzzle DataSource plugin is available. Open freeboard/index-dev.html in your favorite web browser. Under DATASOURCES, click the ADD button. In the dropdown list, you should be able to see Kuzzle Datasource entry.

alt text

Kuzzle Datasource Configuration

Once you clicked on Kuzzle Datasource entry, you get to the plugin settings screen.

alt text

Settings:

Name Description
Kuzzle host The hostname of the machine on which Kuzzle Server instance si running, default is localhost.
Kuzzle port The port through which Kuzzle Server is accessible, default is 7512
Token You can provide a token to be used if anonymous access has been removed. See Kuzzle login API to learn how to generate a JWT encrypted token
Index The Kuzzle index that holds the documents your are interested in.
Collection The Kuzzle collection that holds the documents your are interested in.
Filter The filter the document you are interested in must match. Refer to Koncord documentation for further information about Kuzzle realtime filters. Using {} as filter, will match any document content.

The Kuzzle Datasource plugin will receive a notification for each created document in the specified index/collection that matches the filter.

kuzzle-freeboard-plugin's People

Contributors

etrousset avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kuzzle-freeboard-plugin's Issues

Outdated plugin

Tried to use this in a production environment and after some debugging i found out that the code is outdated regarding how to use Kuzzle-SDK in vanilla js.

Here is the new code so you can update it:

(function() {
  freeboard.loadDatasourcePlugin({
    type_name: "kuzzle_subscribe_data",
    display_name: "Kuzzle Datasource",
    description: "Monitor Kuzzle Documents",
    external_scripts: ["node_modules/kuzzle-sdk/dist/kuzzle.js"],
    settings: [
      {
        name: "kuzzle_host",
        display_name: "Kuzzle host",
        type: "text",
        default_value: "localhost",
        description: "URL to you Kuzzle instance"
      },
      {
        name: "kuzzle_port",
        display_name: "Kuzzle port",
        type: "text",
        default_value: 7512,
        description: "Kuzzle port"
      },
      {
        name: "kuzzle_token",
        display_name: "Token",
        type: "text",
        description:
          "API token retreived using: https://docs.kuzzle.io/api-documentation/controller-auth/login/"
      },
      {
        name: "kuzzle_index",
        display_name: "Index",
        type: "text",
        description: "The index that holds the collection"
      },
      {
        name: "kuzzle_collection",
        display_name: "Collection",
        type: "text",
        description: "The collection"
      },
      {
        name: "kuzzle_subscribe_query",
        display_name: "Subscribe query",
        type: "text",
        description:
          "The subscribe query: https://docs.kuzzle.io/sdk-reference/collection/subscribe/"
      }
    ],
    newInstance: function(settings, newInstanceCallback, updateCallback) {
      newInstanceCallback(new myDatasourcePlugin(settings, updateCallback));
    }
  });

  var myDatasourcePlugin = function(settings, updateCallback) {
    var self = this;
    var currentSettings = settings;

    var callback = (notification) => {
      console.log(notification);
      updateCallback(notification.result);
    };

    var kuzzle = new KuzzleSDK.Kuzzle(
      new KuzzleSDK.WebSocket(currentSettings.kuzzle_host), {
        port: currentSettings.kuzzle_port,
        autoReconnect: true
      }
    );
    kuzzle.on('networkError', error => {
      console.error('Network Error: ', error);
    });
    kuzzle.on('connected', () => {
      console.log('Successfully connected to Kuzzle');
    });

    kuzzle.connect().then(() => {
      kuzzle.realtime.subscribe(currentSettings.kuzzle_index, currentSettings.kuzzle_collection, JSON.parse(currentSettings.kuzzle_subscribe_query), callback);
    })
      .then(() => {
        console.log('Successfully subscribed to document notifications!');
      })
      .catch(error => {
        console.error('Ooops! An error occurred: ', error);
        kuzzle.disconnect();
      });

    self.onSettingsChanged = function (newSettings) {
      currentSettings = newSettings;
    };

    self.updateNow = function () {
      console.log("Pub/Sub model does not allow to update on demand.");
    };

    self.onDispose = function () {
      kuzzle.disconnect();
    };
  };
})();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.