Open bitabs opened 6 years ago
Could this openbci-rx help?
Does node seriaport support react native?
@aj-ptw aparently RN doesn't support serialport
Checkout electron, or the openbci_hub
Are you suggesting to use electron with react native? I have already played with Openbci_hub but only on web-based. However, my target is actually mobile. @aj-ptw
Ah perhaps look into the WiFi shield which would run on react native.
Ah damn, I have only ordered Cyton to work with. Is there really no other alternative to make it work using Cyton? @aj-ptw
@NaseebullahSafi It should be possible to use rn-nodeify and a replacement module such as react-native-usbserial to do this, but you would be treading new ground attempting it, and would likely run into hitches that might need you to look inside things and develop your own workarounds.
Ok Thanks to @baffo32 and @aj-ptw I'm finally able to use the node module OpenBCI in react native. But the issue still remains; in that when OpenBCI module is imported:
const Cyton = require('openbci-cyton');
We get "Maximum call stack size exceeded" error and so I presume that OpenBCI has a node event loop for I/O operations.
Is there anyway way we can fix this?
RangeError: C:/King's_College_London/Final_Year_Project/HeartFailure/node_modules/openbci-cyton/openBCICyton.js: Maximum call stack size exceeded
at validate (C:\King's_College_London\Final_Year_Project\HeartFailure\node_modules\babel-types\lib\definitions\index.js:85:20)
at validator (C:\King's_College_London\Final_Year_Project\HeartFailure\node_modules\babel-types\lib\definitions\index.js:57:7)
at Object.validate (C:\King's_College_London\Final_Year_Project\HeartFailure\node_modules\babel-types\lib\definitions\index.js:190:10)
at validate (C:\King's_College_London\Final_Year_Project\HeartFailure\node_modules\babel-types\lib\index.js:505:9)
at Object.builder (C:\King's_College_London\Final_Year_Project\HeartFailure\node_modules\babel-types\lib\index.js:466:7)
at PluginPass.CallExpression (C:\King's_College_London\Final_Year_Project\HeartFailure\node_modules\babel-plugin-rewrite-require\index.js:85:15)
at newFn (C:\King's_College_London\Final_Year_Project\HeartFailure\node_modules\babel-traverse\lib\visitors.js:276:21)
at NodePath._call (C:\King's_College_London\Final_Year_Project\HeartFailure\node_modules\babel-traverse\lib\path\context.js:76:18)
at NodePath.call (C:\King's_College_London\Final_Year_Project\HeartFailure\node_modules\babel-traverse\lib\path\context.js:48:17)
I don't know how to solve that issue, but just to add resources another alternative is the nodejs-mobile project, which takes the opposite approach of providing a full node runtime on mobile as a background process. No clue if anybody's tried to make serial work with it.
@xloem ok thanks. I'm just about to create a new project for testing with node-js in react native and try to make it work. I'll update you guys. But remember guys, this is a very serious limitation to OpenBCI-Cyton because many people are planning to create mobile apps for cyton rather than a web-based primarily because of portability or whatnot.
@xloem I had a very long chat with the author of that project and although we were able to initialise openbci module in react, we were not able to use the serialport of nodejs.
@aj-ptw I would really appreciate if you could enlighten me. Is there any approach for simply connecting openbci to react native apart from nodejs?
If you want to start developing today, buy the WiFi Shield. You could already be streaming data! The OpenBCI Cyton is in need of a physical hardware update before streaming to a mobile phone.
Apologies if I have misunderstood you. But shouldn't it be possible for streaming data from the cyton to react native as long as the phone is connected to the PC along with the cyton dongle? @aj-ptw
I'm sorry I'm not really sure what react native is I guess. Can you explain to me where react native is running
So react-native is Facebook's framework for cross platform mobile apps, targeting android and ios. It doesnt use node modules, which is why it's so difficult to use openbci-cyton node module in react-native. I have been searching for a solution for this but to no avail. I think the best choice would be then to use wi-fi sheild. Am I right? @aj-ptw
If you want to go direct to mobile phones, you can use the utilities module that's written in pure java-script to parse the raw data over wifi or use any of the existing browser compliant libraries available.
If you want to put a computer on you local network and have that send data to the mobile phone via TCP or something, you could plug the cyton dongle into the PC and stream to the mobile phone. Mobile phone don't have usb plug ports :(
Hey @naseebullahsafi I speak React Native, hell, it’s all do all day long. How and(why) is RN the one thing you thought would connect to a SERIAL port? How do those things even meet? Is there a SERIAL poert on you phone?
(Hey AJ) this repo got real all of a sudden :)
Correct indeed. So my question now would be, If I buy wi-fi shield for this cytone, would I be able to transmit data? If so is it also based on nodejs? Or a general wi-fi module that we can use to listen to?
Is this one of those classic problems where there is a missing ‘fs’ module? We can’t take nodejs for granted. Fs = fileststem npm package . RN doesn’t get access to the FS because it doesn’t run, it’s compiled into totally deterministic code.
From a shell on your machine you can run a nodejs process that will receive data on localhost. It sounds like (RN) you’d want the mobile phone to be the client?
Yes WiFi shield transmits data. It is a server, WiFi receiver on your machine is client, which pipes to command line. So if you can pipe WiFi signal to the process that pings the SERIAL port you should be good.
BUT, how much streaming data do you plan to get through a SERIAL connection? Isn’t that speed measured in mbps? Serial is brutal, isn’t that like 16 steel pins?
Imreading your earlier comment about “node event loop” and trying to understand how that fits in with the React component lifecycle, I think node just runs RN as a compiled bundle, they don’t communicate except maybe through a virtual connection, is that the SERIAL connection?
Yes indeed @octopicorn. It's really pain in the ass to send data from the cytone dongle to react native. Simply put if we can't use nodejs modules in react native, we can't transmit data. But before going on and buying wi-fi shield, I wanted to make sure if it is really possible to transmit data to phone via WiFi shield. And find some implementations of how they do it.
@octopicorn so the data should be streaming continuously until the user stops or closes the app. I'm not entirely sure how much data should be sent per second, but as long as some data is sent to phone, it would be good
How about this? Is this related? https://www.npmjs.com/package/serialport
So I ask you this: what do you have your mobile that can connect to WiFi to stream in to your RN app? Regardless of what transmits on any protocol? What’s your receiver?
@octopicorn ah yes, that was a wrong call. The problem was not with event loop, but rather importing the serial port in react native. But since serial port is node module it wouldn't compile and the app would crash
I’m assuming SERIAL is just a port number you have mapped to a nodejs listener process?
So currently I have a phone, and a cytone board with the dongle, and that's pretty much it really. I connect my cytone to PC via the dongle and tried to use OpenBCI module in react native, but wouldn't work
@octopicornYes correct. But beware, we can't use serialport in react native, as its nodejs module. And we can't use react-native-serialport either because OpenBCI module uses nodes serialport
@NaseebullahSafi I don’t know how much better to help But want to communicate this to you: when you see ‘fs’ error like above it means your non module wants to access filesystem and it can’t because it doesn’t even have the base npm module ‘fs’ to do so.
99% if the time i see this, it means: I’m trying to use an npm idea that was meant from the core torun only with ‘fs’ access as a dependency.
@octopicorn Really appreciate your time helping me understand some misconception. And after working on it for 3 days straight I now understand the reason behind it, but sadly there's literally nothing I can do to make it work.
How many channels do you want? There is a 2 channel 125Hz BLE driver that I wrote for Cyton that is still alpha but would allow you to at least get data from the Cyton. Although you would have to reprogram the physical RFDuino on the Cyton and would not be able to use the GUI because the dongle would no longer work. WiFi can definitely go to any web browser, which means your react mobile app can talk to the device!
I see. Tbh Id just need 2 or 1 channel. What kind of changes would there be in rfduino? @aj-ptw
You see, willing to opt out from GUI and the dongle because the main priority is to create data transmission between cytone to react native.
Since doing an app for ekg/ecg, I'd only need 1 or 2 channel instead of all 8 .
Okay and you are able to use BLE inside react native?
Is there any possibility for the OpenBCI community to use the BLE for only 2 channels? As I fit in that category, and would really appreciate to use it.
The instructions and drivers are linked in the bottom.
You could also get a ganglion instead of the cyton, no guarantee the device will stream to it though
Ok thank you, I'll try to apply the same changes you made to BoardWithBLE.ino
to make my cyton look for BLE
@aj-ptw I see you have this repo
https://github.com/PushTheWorld/OpenBCI_NodeJS_Cyton_BLE
Cant I just use this? I'm confused what changes do I have to do in my side of Cyton arduino.
I'm trying to use OpenBCI Cyton in react native application. However the issue is that I can't import it in react native. Is there a way to use Cyton in react native?
This is the error I get:
and I try to use it like so: