1.0.5 • Published 2 years ago

jmri-cli v1.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

JMRI - websocket - NodeJS

Full access to the railroad model with NodeJS via JMRI JSON Servlet. Feedback is available through subscription to events.

The JMRI JSON Services provide access to JMRI via JSON data objects via a RESTful interface via a socket interface over WebSockets.

Prerequisites

JMRI server run and connected to your DCC Command station. To start getting events you have to call a get or a set function for the objects (sensor, throttle, turnout).

Installation

npm install jmri-cli

API

Initialize

const JMRI = require('jmri-cli');
let myModel = new JMRI("http://192.168.1.30:12080/json/");

Methods

setThrottle({"name": "M62", "address": 5, "speed": 0.6});

getTurnout('XT1');

getSensor('XS509');

Example

myModel.ee.on('hello', data => {
    console.log('hello event');
    console.log('[i] railroad ' + data.railroad + ' is connected');
    test();
})
myModel.ee.on('sensor', data => {
    console.log('sensor event');
    console.log("[i] sensor " + data.name + ' state = ' + data.state);
})
myModel.ee.on('throttle', data => {
    console.log('throttle event');
    console.log('throttle data for ' + data.name + ' speed: ' + data.speed);
})
myModel.ee.on('turnout', data => {
    console.log('turnout event');
    console.log("[i] turnout " + data.name + ' state = ' + data.state);
})

const test = () => {
    console.log('...running test init');
    myModel.setThrottle({"name": "M62", "address": 5, "speed": 0.6});
    myModel.getSensor('XS509');
    myModel.getSensor('XS510');
    myModel.getSensor('XS511');
    myModel.getTurnout('XT1');
    myModel.getTurnout('XT6');
}
1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago