openbci-archive / OpenBCI_NodeJS

Node.js SDK for the all OpenBCI Biosensor Boards
https://www.npmjs.com/package/openbci
137 stars 52 forks source link

Uncaught ReferenceError: OpenBCIBoard is not defined #137

Closed compmonks closed 7 years ago

compmonks commented 7 years ago

Hi all, sorry for the noob question but I am currently banging my head trying to make openbci running. in my case I have the following node structure:

myapp
-bin
-lib
-routes
-run
-views
-etc
-node-modules
--openbci
-public
--app.js
--index.html
--js
--styles
--...

my app.js file loads openbci

var express = require('express');
var app = express();
app.use(express.static('public'));
var openBCIBoard = require('openbci').OpenBCIBoard;
app.listen(myPort);

my index.html file then loads a nav.js file where I try to get openbci streaming <script src="/planetoftheapes/javascript/nav.js"></script>

the specific function in the js file looks like this

function toggleOpenBCI() {
    var ourBoard;
        // start openBCI test
        ourBoard = new OpenBCIBoard({ //openBCIBoard called in app.js
            verbose: true,
            simulate: true
            }); // synthetic mode and verbose for this test
        ourBoard.autoFindOpenBCIBoard().then(portName => {
          if (portName) {
            /**
             * Connect to the board with portName
             * Only works if one board is plugged in
             * i.e. ourBoard.connect(portName).....
             */
            ourBoard.connect(portName) // Port name is a serial port name, see `.listPorts()`
              .then(() => {
                ourBoard.on('ready',() => {
                  ourBoard.streamStart();
                  ourBoard.on('sample',(sample) => {
                    /** Work with sample */
                    for (var i = 0; i < ourBoard.numberOfChannels(); i++) {
                      console.log("Channel " + (i + 1) + ": " + sample.channelData[i].toFixed(8) + " Volts.");
                      // prints to the console
                      //  "Channel 1: 0.00001987 Volts."
                      //  "Channel 2: 0.00002255 Volts."
                      //  ...
                      //  "Channel 8: -0.00001875 Volts."
                    }
                  });
                });
              });
          } else {
            /** Unable to auto find OpenBCI board */
            console.log('Unable to auto find OpenBCI board');
            console.log('Trying on Manual Connection Port...');
            // add manual connection port handle here...
          }
        });
}

But it returns me an Uncaught ReferenceError: OpenBCIBoard is not defined which tells me that I cannot pass the openBCIBoard variable like this. Could you please tell me how to make it work?

andrewjaykeller commented 7 years ago

Your problem is here:

var express = require('express');
var app = express();
app.use(express.static('public'));
var openBCIBoard = require('openbci').OpenBCIBoard;
app.listen(myPort);

should be:

var express = require('express');
var app = express();
app.use(express.static('public'));
var OpenBCIBoard = require('openbci').OpenBCIBoard; // Note I made the variable caps
app.listen(myPort);

Please see the getStreaming.js example

compmonks commented 7 years ago

thanks for your answer and pointing out the typo. Unfortunately, the issue remains. I will try to look again Thanks

andrewjaykeller commented 7 years ago

Are you running it on a node server?

compmonks commented 7 years ago

Yes

andrewjaykeller commented 7 years ago

Please post a link to your source code.

compmonks commented 7 years ago

here you go : https://github.com/compmonks/neurodesign

andrewjaykeller commented 7 years ago

Oh wow that's confusing haha I'm not sure how to help you with it! Maybe check out @neurojs or @castillo-io can help you!

compmonks commented 7 years ago

do you know any working example on a node server by any chance?

andrewjaykeller commented 7 years ago

Did you check out @neurojs