The purpose of Sigreadmonitor is to provide an easy way of communicating with the Alkit Signal Brooker. 

Example of usage: 

// Import package
const sigreadTcp = require('sigreadmonitor').tcpSocket;

// Create a connection.
// This will return a "handler". This handler is used to recieve data, and to handle different events.
var handler = sigreadTcp.create({
    ip: 'localhost',
    port: 31415,
});

// Set subscribed signals to return timestamps
sigreadTcp.useTimestamp(handler, true);

// Handle broken sockets
handler.on('tcp-end', () => {
    console.error('TCP connection ended');
});

// Handle errors
handler.on('error', (err) => {
    console.error(err.message);
    sigreadTcp.disconnect(handler);
});

// Handle data. The data comes pre-parsed, into managable objects put into arrays.
handler.on('data', (data) => {
    data.forEach(dataElement => {
        console.log(dataElement.timestamp + ' ' + dataElement.signal + ': ' + dataElement.value);
    });
});

// Create an async function in order to execute several asynchronous functions in sequence
var getSigreadInfo = async function (sigreadTcp, handler) {
    try {
        // The following functions all return "js promises"
        // Thus, you can extract the information without worrying about callbacks.
        var setupName = await sigreadTcp.getActiveSetup(handler);
        var setups = await sigreadTcp.getSetupList(handler);
        var recorders = await sigreadTcp.getRecorderList(handler, setupName);
        var signals = await sigreadTcp.getSignalList(handler);

        let information = {
            setupName: setupName,
            setups: setups,
            recorders: recorders,
            signals: signals
        }

        console.log('Current measurement setup: ' + setupName);
        console.log('Available measurement setups: ' + setups);
        console.log('Available recorders: ');
        recorders.forEach(recorder => {
            console.log('name: ' + recorder.name + ' - recording: '+recorder.recording);
        });
        console.log('Available signals: ')
        signals.forEach(signal => {
            console.log('name: '+signal);
        });

        return;
    } catch (err) {
        console.log('error: ' + err.message);
    }
}

// Execute, and subscribe to some signals
getSigreadInfo(sigreadTcp, handler);
sigreadTcp.subscribe(handler, ['WICE_Generic_Internal.WCU_Battery', 'WICE_Generic_Internal.Usage_CPU']);