Code Monkey home page Code Monkey logo

omi-odf-nodejs's Introduction

Omi Client

This is a very simplistic WebSocket based client for communicating with a O-MI Node, using O-DF formatted messages.

Getting started

Start a O-MI Node

Download the reference server implementation from:

https://github.com/AaltoAsia/O-MI/releases

We used this one: https://github.com/AaltoAsia/O-MI/releases/download/0.8.2/o-mi-node-0.8.2-warp10.tgz

Extract it to an appropriate location.

Edit the conf/application.conf. Ensure the localhost is not commented out in the IP whitelist section.

input-whitelist-ips=[	
        "127.0.0.1"
]

Ensure you have java 8 or later.

In a console/command line type java -version, response should be something like this:

greg@desktop ~/o-mi-node-0.8.2-warp10 $ java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

Run the server.

greg@desktop ~/o-mi-node-0.8.2-warp10 $ ./bin/o-mi-node

The first startup will take some few minutes to start, be patient.

Run the example

Create a working directory for your project and install this package there.

npm install omi-odf

Create a app.js with the following sample code:

var OmiClient = require('omi-odf').OmiClient;
var inspect = require('util').inspect;

var host = 'ws://localhost:8080';
var omiClient = new OmiClient(host);

omiClient.once('ready', function() {
    console.log("OmiClient connected to "+ host +'.');
    
    var name = 'MyDevice';
    var path = 'Your/Path/Things/'+name;
    var ep = 'relay';

    // ensure the instance in the O-MI node by issuing a write command
    omiClient.write(path, ep, false);

    // subscribe to changes from "MyDevice"
    omiClient.subscribe(path, null, {}, function(ep, data, opts) {
        console.log("Subscribe:", ep, data, opts);
    });

    // write ep to true, which should trigger subscription callback
    setTimeout(() => { omiClient.write(path, ep, true); }, 500);
    
    setTimeout(() => {
        omiClient.read(path, ep, function(ep, value, opts) {
            console.log('Read:', ep, value, opts);
        });
    }, 600);
});

omiClient.once('close', function() {
    console.log("OmiClient websocket connection was lost.");
    process.exit(1);
});

Run the program:

node app.js

Develop

This code is available at GitHub:

git clone https://github.com/ControlThings/omi-odf-nodejs.git

Acknowledgements

Part of this work has been carried out in the scope of the project bIoTope which is co-funded by the European Commission under Horizon 2020 program, contract number H2020-ICT-2015/688203.

omi-odf-nodejs's People

Contributors

tk009 avatar akaustel avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar  avatar

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.