GithubHelp home page GithubHelp logo

pushtheworld / openbci_nodejs_cyton_ble Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 561 KB

NodeJS Driver for Running 2-Channel Cyton Over BLE

License: BSD 3-Clause "New" or "Revised" License

JavaScript 100.00%

openbci_nodejs_cyton_ble's People

Watchers

 avatar  avatar  avatar  avatar

openbci_nodejs_cyton_ble's Issues

There's no emitter for Cyton Board.

Hi there,

Could you please add OBCIEmitterCytonFound because there exists an emitter for Ganglion OBCIEmitterGanglionFound but not for Cyton. Hence one part of the code never runs

Currently

    // this code is never invoked because I presume  "OBCIEmitterGanglionFound" looks for Ganglion
    Cyton.once(constants.OBCIEmitterCytonFound, () => {
      console.log("hello im here");
    });

    Cyton.once(constants.OBCIEmitterBlePoweredUp, () => {
      Cyton.searchStart().catch(e => console.log(e))
    });

    if (Cyton.isNobleReady()) {
      console.log(`noble is ready so starting scan`);
      Cyton.removeListener(constants.OBCIEmitterBlePoweredUp, () => {
        Cyton.searchStart().catch(e => console.log(e));
      });
    } else {
      console.log(`noble is NOT ready so waiting starting scan`);
    }

Thanks

How to enable BLE for Cytone?

I've managed to get my hands on BLE and everything is ready. One thing remains is that the Cyton is not publicly visible, even though its switched to BLE mode instead of PC.

Is there any modification that we must do?

In the post, we are told that the RFDuino must import the RFDuino.h. How do we do this in order to allow BLE?
capture

What should happen if there's no service found for Cyton?

Currently, when I call the connect method, it throws an error that services are null. Which is true because When I printed, this was shown:
capture

Here's what I have:

    Cyton.once(constants.OBCIEmitterRFduino, (peripheral) => {

      Cyton.searchStop().then(() => {
        console.log("Hello:=> ", peripheral);
        console.log(`search stopped`);
        //console.log(peripheral.services);
        Cyton.connect(peripheral).catch(e => console.log(e));
      }).catch(e => console.log(e));
    });

    Cyton.once(constants.OBCIEmitterBlePoweredUp, () => {
      Cyton.searchStart().catch(e => console.log(e))
    });


    if (Cyton.isNobleReady()) {
      console.log(`noble is ready so starting scan`);
      Cyton.removeListener(constants.OBCIEmitterBlePoweredUp, () => {
        Cyton.searchStart().catch(e => console.log(e));
      });
    } else {
      console.log(`noble is NOT ready so waiting starting scan`);
    }

Now the question is, why is the service null, and what should we do when it is null?

Update

The weird thing is, when I run it now, although the [services] exist, but the error still shows:

capture

And If I backtrack the error, it falls here:

capture

Once connected, how to start receiving the data

So currently, everything boils down to Operating system. "Noble" which is used to connect devices cannot be used in mobile apps. Therefore There's a Reacts version of Noble which can be used to connect the device via BLE (which what they've done essentially is converted the node's version of noble into react native, and deep down their structure, they've used Node's noble as a native module.

With this module so far I've been successfully connecting the device via Bluetooth; and everything is ready....except one thing. How do we set the board to start sending data? I've been examining openBCICytonBLE.js and the crucial part I think is this:

      this._rfduinoService.once(k.OBCINobleEmitterServiceCharacteristicsDiscover, (characteristics) => {
        if (this.options.verbose) console.log('Discovered ' + characteristics.length + ' service characteristics');
        for (let i = 0; i < characteristics.length; i++) {
          // console.log(characteristics[i].uuid);
          if (characteristics[i].uuid === k.RFduinoUuidReceive || characteristics[i].uuid === rfduinoUuidReceiveLong) {
            if (this.options.verbose) console.log("Found receiveCharacteristicUUID");
            this._receiveCharacteristic = characteristics[i];
          }
          if (characteristics[i].uuid === k.RFduinoUuidSend || characteristics[i].uuid === rfduinoUuidSendLong) {
            if (this.options.verbose) console.log("Found sendCharacteristicUUID");
            this._sendCharacteristic = characteristics[i];
          }
        }

        if (this._receiveCharacteristic && this._sendCharacteristic) {
          this._receiveCharacteristic.on(k.OBCINobleEmitterServiceRead, (data) => {
            // TODO: handle all the data, both streaming and not
            this._processBytes(data);
          });

          // if (this.options.verbose) console.log('Subscribing for data notifications');
          this._receiveCharacteristic.notify(true);

          this._connected = true;
          this.emit(k.OBCIEmitterReady);
          resolve();
        } else {
          reject('unable to set both receive and send characteristics!');
        }

The issue was when I was using your module was that we weren't receiving any characteristics hence we couldn't get into this line:

this._processBytes(data);

Which is presume is the line that sends a command to the device to start sending data?

Now when we use the React's version, the following code will get us the following:

this.startScan();

    BleManager.connect(`${RFDuinoID}`).then(() => console.log("connected") ).catch( e => console.log( e ));

    setTimeout(() => {
      BleManager.retrieveServices(RFDuinoID).then(peripheral => {
        console.log("peripheral ", peripheral);
        setTimeout(() => {
          BleManager.startNotification(RFDuinoID, "2220", "2221").then(() => {
            console.log('Started notification on ' + RFDuinoID);
            setTimeout(() => {
              NativeAppEventEmitter.addListener('BleManagerDidUpdateValueForCharacteristic', (data) => {
                // this line tries to read data, but can't since we havent told the device to start
                console.log("BMDUVFC: ", data.value);
              });
            }, 500);
          }).catch((error) => console.log('Notification error', error));
        }, 200)
      })
    }, 900) // <== 1

and the result will be this:
capture

This is actually great because we have no established a connection and everything is ready.

Now the issue is, in your case your somehow sending a command to the device to start sending data. I'm not sure if its in byte array or buffer. But the whole thing now boils down to how to tell the device to send data. Because we're able to get the services & charachteristics, but now I'm not sure what to do next.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.