Node-RED


#1

Will Flotilla once shipped include Node-RED nodes as indicated in a stretch goal ?


#2

Proper Node-Red support wont be ready when Flotilla ships- we’re busy focusing on the Flotilla Dock software, the Serial to Web Sockets daemon, Rockpool and the Python API ( if you could call working on 5 different projects in 5 different languages focusing! ), which leaves little time to explore Node-Red.

However, I have explored Node-Red and found that, as a side effect of the Flotilla Daemon being a web-sockets server, you can quite easily talk directly to it in Node-Red and digest the Flotilla-speak into something useful using custom functions.

Here’s an example custom function which takes a Flotilla message and splits out update, connect and disconnect events into different outputs:

switch(msg.payload[0]){
    case 'u': // Flotilla Update
        var d, c, m, details;
        d = msg.payload.trim().split(' ');
        d.shift()
        details = d.shift().split('/');
        c = details[0];
        m  = details[1];
        node.send([
            {payload:{'event':'update','channel':c, 'module':m, 'values':d}},
            null,
            null
            ]);
        break;
    case 'd': // Flotilla Disconnect
        return null;
    case 'c': // Flotilla Connect
        return null;
    default:
        return null;
}

And if you wanted to look at the update events and filter out the value of a Dial, on Channel 2 you could stack up another custom function like so:

if( msg.payload.module == 'dial' && msg.payload.channel == '2'){
    msg.payload = msg.payload.values[0];
    return msg;
}
return null;

The payload.values would be an array of update values- in this case we’re talking about a Dial value from 0 to 1023 which only has one value, so we pick index 0.

The result? A number from 0-1023 which you can then pipe wherever you like.

As for updating Flotilla modules with new instructions, you simply need to construct the right command in Node-Red which is extraordinarily simple and educational with custom functions. Here’s an example of a motor being driven from the Dial we just read:

var speed = 100 * ((msg.payload/1023.0) - 0.5);
msg.payload = 's 0 ' + speed; // Send speed value to Channel 0
return msg;

There will be more complete coverage of Flotilla-speak in the documentation, but basically to send a command to any device you address it by channel number ( there can only be one device per channel ) followed by space, then a comma-separated list of values. Updating a motor on Channel 0 is as simple as:

s 0 -50

Or

s 0 50

Node-Red rocks at all this stuff already, so you wont be high-and-dry from the get-go, but we plan on releasing a set of modules that make this easier and much less dependent on spaghetti custom function code.