NTX-McGill/NeuroTechX-McGill-2021

Software (backend): Stream data from OpenBCI device

Closed this issue · 3 comments

mlej8 commented

Adapt NeuroTechX-McGill-2021/software/data_collection_platform/backend/dcp/bci/stream.py to stream data from the OpenBCI device.

@mlej8 should the data be streamed to flask using a REST endpoint or a socket?
Also are we using a celery worker to run the stream.py service?

mlej8 commented

There will be two processes:

  1. one process streaming data from the BCI device to our computer (Process 1)
  2. one process running the backend of the flask application (Process 2)

These two processes need to communicate with each other. This can either be done through message passing (for example, you can use a shared queue https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Queue) or shared variables.

In this case, I believe we only need to communicate the current letter that is being selected from the flask application (Process 2) to Process 1. This can be done through a shared variable (have a look at shared.py in the repo). While process 1 streams data in from the BCI device, it will temporarily hold the data in a buffer (you can choose a data structure that is appropriate for this). Once the buffer is full, it has to write everything to the database while labeling everything as the character that is currently selected. This can either be done directly from stream.py or you can send the data that is in the buffer to the flask application so that it will do the writing using SQLAlchemy (ORM). Think of which would be a better solution. Feel free to schedule a call with me if this is not clear.

mlej8 commented

Also, another issue you have to think about is "when to start buffering streamed data", because we will not always be collecting data. We are only collecting data if the user has selected a character on the keyboard. Therefore, you might want to add a check such that we are only collecting (append to the buffer) data when the selected character is not null..