Johnny-five Version 2.1 under Windows

As described in my post "Problem with johnny-five version 2.0" fro May 15, the "new" keyword is required in order to create an instance of the Board class. This keyword cannot be inserted in the corresponding entry in the settings file, even the notation:
j5board:require("johnny-five").(new Board({port: "COM5", repl:false}))
did not function. I think this should be changed in node-red.
However I found a workaround:

  1. insert in Class Board in johnny-five Board.js the following function:
    static create(options = {}) {
    return new Board(options);
    }
  2. change the settings entry to:
    j5board:require("johnny-five").Board.create({port: "COMx", repl:false})

I am not sure about conformity and efficiency concerning the class handling in javascript, but at least the workaround functions.
Nevertheless should node-red allow the new keyword in the settings file.

You can simply add a const at the top of the settings file, create your instance (using new) then set the settings entry to your const variable.

Above module.exports = { ...

const j5 = new blahblahblah(x,y,z);

Inside module.exports = { ...

   j5board:j5,

Thank you very much for your prompt help!

However const j5b = new require("johnny-five").Board({port: "COM5", repl:false}); did not function, but

const j5f = require("johnny-five");

const j5b = new j5f.Board({port: "COM5", repl:false}); before module.exports does function.

Thanks again, this is clearly a better solution.

Yes, of course you need to do the require first :+1: (I should have been more explicit sorry)

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.