Sending Electroencephalography(EEG) data over Socket.io using Muse EEG headset
This is an example built on the muse sdk example code and socket.io java client code, modified to communicate EEG data to a web server using socket.io.
create new Constants class due to git ignore for the Constants file. place your ip for port 3000 for socket .io in the android javafile Constants
public class Constants{
//replace with your ip/server address :portserver is listening on
public static final String CHAT_SERVER_URL = "http://your ip addres:3000";
}
- If you are running the the server on your local computer make sure your mobile device is on the same network
- Your network setting is set to private instead of public
- Run the index.js file on the server
- launch the app
//add other listenners for other signals if you want
socket.on("alphaData",function(data){
//send back to requesting client
//calling function in adroid app to plot the data point on android graph
socket.emit("alphaDataEcho",{
point: data
});
//console.log(data); for testing
});
mSocket.emit("alphaData",alphaBuffer[0]);
//or
//perfered
//use the built object wich holds all the main eeg vals
mSocket.emit("alphaData",mEEGdata.getAlphaRef().getelem1());
private Emitter.Listener onAlphaDataEcho = new Emitter.Listener() {
@Override
public void call(final Object... args) {
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
JSONObject data = (JSONObject) args[0];
String point;
try {
point = data.getString("point");
} catch (JSONException e) {
Log.e(TAG, e.getMessage());
return;
}
mDataEchoTx.setText(point);
//plot data if plot is true
if(plotData && plot){
if(point.equals("NaN")){
addEntry(0);
}
else{
addEntry(Float.parseFloat(point));
}
plotData =false;
}
}
});
}
};
- Main socket.io java client git example https://github.com/socketio/socket.io-client-java
- mpandroid chart https://www.youtube.com/watch?v=QEbljbZ4dNs
- Socket.io notes/playlist https://drewww.github.io/socket.io-benchmarking/