pushtheworld / openbci_nodejs_cyton_ble Goto Github PK
View Code? Open in Web Editor NEWNodeJS Driver for Running 2-Channel Cyton Over BLE
License: BSD 3-Clause "New" or "Revised" License
NodeJS Driver for Running 2-Channel Cyton Over BLE
License: BSD 3-Clause "New" or "Revised" License
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
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?
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:
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?
The weird thing is, when I run it now, although the [services
] exist, but the error still shows:
And If I backtrack the error, it falls here:
Hi there,
I'm unable to install this package because it doesn't exist in npm.
Thanks
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
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.