This project takes brain wave readings from a MindWave Mobile 2+, transmits them to an iOS app via Bluetooth LE. The iOS app makes calls to a remote Node server, which is a minimal REST API, passing off the brain wave sample. The Node server stores the data on a MongoDB server. The MongoDB server is then exposed to business intelligence applications use with MongoDB BI Connector. Lastly, using Tableau Professional Desktop, the data is accessed and visualizations created.
- MindWave Mobile 2+
- iOS App (tentatively named Mind Wave Journaler; Swift)
- REST Server (mind-wave-journaler; NodeJS)
- MongoDB BI Connector Server
- Tableau Desktop Professional
The end result is a system which could allow a remote EEG analyst to examine samples nearly in real time.
Below, I’m going to show how I was able to setup the system. But, before that a few words of warning.
This isn’t a hacker friendly project. It relies on several paid licenses, an Apple Developer License ($99) and Tableau Desktop Professional ($10,000,000,000 or something). Of course, the central piece of hardware, the MindWave Mobile, is also $99, but I think that one is fair. Oh! Let’s not forget, even though you bought an Apple Developer license, you still need a Mac (or Hackintosh) to compile the app.
However, as a proof-of-concept, I think it’s solid. Hopefully a good hacker will be able to see how several tweaks in the system could make it dirt cheap to deploy.
Mimimum Viable Hack..er, Product
The source code provided here is a minimally viable. Fancy words meaning, only base functionality was implemented. There many other things which could be done to improve each piece of the system.
Not to be a douche, but please don’t point them out. That’s the only thing I ask for providing this free information.
There are many improvements I know can be made. The reason they were not made had nothing to do with my ignorance (well, at least a majority of them), but rather my time constraints.
I Hate Tableau
That’s it. I hate Tableau.
Let’s make a list of what’s needed before beginning this project.
- Mac (to compile the iOS app)
- MindWave Mobile 2+
- A remote server running Ubuntu 16.04 (theoretically a local server will work, but you’ll be on your own)
- Apple Developer License
- Xcode, with Swift 4.1
- MongoDB Running on Ubuntu
- MongoDB BI Connector Server
- A business intelligence platform with remote connection ability
Regarding the business intelligence platform–if anyone has a free suggestions, please leave them in the comments below. The first improvement I’d like to the entire system is to get away from Tableau. Have I mentioned I hate it?
Ok, let’s get started!
Step 1: iOS App
I’m going to assume you have Xcode installed.
Step 1.1: Install CocoaPods
CocoaPods is a package handler for Xcode. We will be using it to install Alamofire, which a Swift library for making HTTP requests. We will need HTTP call support as we will call our server to store the EEG samples.
sudo gem install cocoapods
After you hit Return it will prompt for your password
Step 1.2: Setup Xcode Project
Now, let’s setup a project folder. This is main folder where all the iOS app code will live. It’s a bad habit, but I usually put mine on the Desktop.
Open Xcode and select “Create a new Xcode proejct”
Then select “Single View App” and click “Next”
Let’s call the project
MindWaveJournaler and click “Next”
Choose your Desktop as location for the project and click “Create”
Step 1.3: Development Environment Setup
You’ve created a Project Folder, but we have to setup the project folder to be used with CocoaPods. After, we will use CocoaPods to install Alamofire.
Back in the terminal, type:
cd ~/Desktop/MindWaveJournaler pod init
This creates a
Podfile in the root folder of our project. We can list CocoaPod packages in the Podfile and run
pod install in the same directory, this will cause CocoaPods to install all the packages we listed.
Sadly, we are really only doing this for Alamofire right now. But, later, when we start building on to this app it will allow us to quickly access third-party frameworks.
Ok, back to typing:
open -a Xcode Podfile
This will open the Podfile for editing in Xcode. Now let’s insert the our desired pod information.
Copy information below and paste it into your file:
# Uncomment the next line to define a global platform for your project platform :ios, '11.4' target 'MindWaveJournaler' do # Comment the next line if you're not using Swift and don't want to use dynamic frameworks use_frameworks! # Pods for MindWaveJournaler pod 'Alamofire', '~> 4.7' target 'MindWaveJournalerTests' do inherit! :search_paths # Pods for testing end target 'MindWaveJournalerUITests' do inherit! :search_paths # Pods for testing end end
You may notice the only changes we made were
platform :ios, '11.4' ... pod 'Alamofire', '~> 4.7'
These lines tell CocoaPods which version of iOS we are targetting with our app (this will silence a warning, but shouldn’t be required). The other, is telling CocoaPods which version of Alamofire we’d like to use on this project.
Ok, now let’s run this Podfile.
Back in the same directory as the Podfile type:
You should see CocoaPods do its thing with output much like below.
Step 1.4: Install NeuroSky iOS SDK
NeuroSky has a “Swift SDK.” Really, it’s an Objective-C SDK which is “bridged” into Swift. Essentialy, this means we won’t be able to see what’s going on the SDK, but we can use functions from the pre-compiled binaries.
I’ve not been impressed with NeuroSky’s website. Or the SDK. It does the job, but not much more.
Anyway, the SDK download is annoyingly behind a sign-up wall.
Visit the link above and click on “Add to Cart”
Then “Proceed to Checkout”
Lastly, you have to enter your “Billing Information.” Really, this is only your email address, last name, street address, city, and zip.
(Really NeuroSky? This is very 1990.)
Eh, I made mine up.
Anyway, after your enter information click, then click “Continue to PayPal” (What? I just provided my information…) You should be rewarded with a download link. Click it and download the files.
Unzip the files and navigate
iOS Developer Tools 4.8 -> MWM_Comm_SDK_for_iOS_V0.2.9 -> lib
Copy all files from the
lib folder into the main directory of the
MindWaveJournaler project folders.
Step 1.5: Workspace Setup
CocoaPods works by creating a
.xcworkspace file. It contains all the information needed to compile your project with all of the CocoaPod packages installed. In our case the file will be called
MindWaveJournaler.xcworkspace. And every time you want to work on your project, you must open it with this specific file.
It can be a bit confusing because Xcode created a
.xcodeproj file which is tempting to click on.
Go ahead and open the
MindWaveJournaler.xcworkspace file. The workspace should open with one warning, which we will resolve shortly.
But first, another caveat. CoreBluetooth, Apple’s Bluetooth LE Framework, only works when compiled for and run on an actual device. It does *not work in the iOS Simulator.* Once upon a time it did, if your Mac had the hardware, however, my version of the story is Apple didn’t like having to support the confusion and dropped it.
Moving on. Click on the yellow warning. Then click on the warning in the sidebar. This should create a prompt asking if you’d like to make some changes. This should automatically make some tweaks to the build settings which should make our project mo’ betta.
This should silence the warning and make your project error free. Go ahead and hit
Play button and let it compile to the simulator (we aren’t testing the Bluetooth, so it’s ok). Everything should compile correctly, if not, just let me know the specifics of your problems in the comments.
Step 1.5: Internal Workspace Setup
There are still a few tweaks we need to make to the Xcode workspace to get everything work.
First, open the
ViewController.swift file and add
import Alamofire right below
import UIKit. If auto-complete lists Alamofire as an option you know the workspace is detecting its presence. Good deal.
Now, for Alamofire to be able to securely make HTTP request an option needs to be added to the
Info.plist file. I scratched my head as to why the HTTP calls were not being made successfully until Manab Kumar Mal’s StackOverflow post:
Ok, following his instructions open up the
Info.plist file in your MindWaveJournaler folder. Now add an entry by right-clicking and selecting
Add Row. Change the
Application Category to
NSAppTransportSecurity and make sure it’s set as
dictionary. Now, click the plus sign by the new dictionary and set this attribute as
NSAllowsArbitraryLoads, setting the type
bool, and the value as
Step 2: MongoDB
Step 3: NodeJS Server
Step 4: MongoDB BI Connector
Step 5: Connecting Tableau
To install CocoaPods we will install prerequisites Homebrew.
Installing Homebrew is pretty simple. Open your terminal and paste the following:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
It will prompt you for the password, as it needs root access to setup correctly. Then, it clones Homebrew from Github and runs a script to set it up. After a bit, you should end with “Installation Successful”.
Now Homebrew is setup, let’s install CocoaPods