Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cpp-qt/cortexclient/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include <QJsonObject>

/*
* To get a client id and a client secret, you must connect to your Emotiv
* account on emotiv.com and create a Cortex app.
* https://www.emotiv.com/my-account/cortex-apps/
* Enter your application Client ID and Client Secret below.
* You can obtain these credentials after registering your App ID with the Cortex SDK for development.
* For instructions, visit: https://emotiv.gitbook.io/cortex-api#create-a-cortex-app
*/
static const QString ClientId = "The client id of your Cortex app goes here";
static const QString ClientSecret = "The client secret of your Cortex app goes here";
Expand Down
6 changes: 3 additions & 3 deletions csharp/CortexAccess/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
static class Config
{
/*
* To get a client id and a client secret, you must connect to your Emotiv
* account on emotiv.com and create a Cortex app.
* https://www.emotiv.com/my-account/cortex-apps/
* Enter your application Client ID and Client Secret below.
* You can obtain these credentials after registering your App ID with the Cortex SDK for development.
* For instructions, visit: https://emotiv.gitbook.io/cortex-api#create-a-cortex-app
*/
public static string AppClientId = "put_your_application_client_id_here";
public static string AppClientSecret = "put_your_application_client_secret_here";
Expand Down
4 changes: 2 additions & 2 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ Before running the examples, please ensure you have completed the following step
3. **Obtain an EMOTIV Headset or Create a Virtual Device**:
- Purchase a headset from the [EMOTIV online store](https://www.emotiv.com/), **or**
- Use a virtual headset in the EMOTIV Launcher by following [these instructions](https://emotiv.gitbook.io/emotiv-launcher/devices-setting-up-virtual-brainwear-r/creating-a-virtual-brainwear-device).
4. **Get Client ID & Secret**: Log in to your Emotiv account at [emotiv.com](https://www.emotiv.com/my-account/cortex-apps/) and create a Cortex app. [Register here](https://id.emotivcloud.com/eoidc/account/registration/) if you don't have an account.
5. **Authorize Examples**: The first time you run these examples, you may need to grant permission for your application to work with Emotiv Cortex.
4. **Create your Cortex App**: Once you register your Cortex App ID, you will receive a Client ID and Client Secret, which serve as unique identifiers for your software application. For instructions, visit: https://emotiv.gitbook.io/cortex-api#create-a-cortex-app

---

Expand All @@ -46,6 +45,7 @@ Demonstrates how to:
- Create a new record
- Stop a record
- Export recorded data to CSV or EDF
- Query records and request to download record data
See: [Records](https://emotiv.gitbook.io/cortex-api/records)

### 4. `marker.py` — Inject Markers
Expand Down
523 changes: 337 additions & 186 deletions python/cortex.py

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions python/facial_expression_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,11 @@ def on_inform_error(self, *args, **kwargs):

def main():

# Please fill your application clientId and clientSecret before running script
your_app_client_id = ''
your_app_client_secret = ''
# Enter your application Client ID and Client Secret below.
# You can obtain these credentials after registering your App ID with the Cortex SDK for development.
# For instructions, visit: https://emotiv.gitbook.io/cortex-api#create-a-cortex-app
your_app_client_id = 'put_your_app_client_id_here'
your_app_client_secret = 'put_your_app_client_secret_here'

# Init Train
t=Train(your_app_client_id, your_app_client_secret)
Expand Down
8 changes: 5 additions & 3 deletions python/live_advance.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,11 @@ def on_inform_error(self, *args, **kwargs):

def main():

# Please fill your application clientId and clientSecret before running script
your_app_client_id = ''
your_app_client_secret = ''
# Enter your application Client ID and Client Secret below.
# You can obtain these credentials after registering your App ID with the Cortex SDK for development.
# For instructions, visit: https://emotiv.gitbook.io/cortex-api#create-a-cortex-app
your_app_client_id = 'put_your_app_client_id_here'
your_app_client_secret = 'put_your_app_client_secret_here'

# Init live advance
l = LiveAdvance(your_app_client_id, your_app_client_secret)
Expand Down
9 changes: 5 additions & 4 deletions python/marker.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ def on_warn_record_post_processing_done(self, *args, **kwargs):
# - Please reference to https://emotiv.gitbook.io/cortex-api/ first.
# - Connect your headset with dongle or bluetooth. You can see the headset via Emotiv Launcher
# - Please make sure the your_app_client_id and your_app_client_secret are set before starting running.
# - In the case you borrow license from others, you need to add license = "xxx-yyy-zzz" as init parameter
# - Check the on_create_session_done() to see a record is created.
# RESULT
# - record data then inject marker each 3 seconds
Expand All @@ -184,9 +183,11 @@ def on_warn_record_post_processing_done(self, *args, **kwargs):

def main():

# Please fill your application clientId and clientSecret before running script
your_app_client_id = ''
your_app_client_secret = ''
# Enter your application Client ID and Client Secret below.
# You can obtain these credentials after registering your App ID with the Cortex SDK for development.
# For instructions, visit: https://emotiv.gitbook.io/cortex-api#create-a-cortex-app
your_app_client_id = 'put_your_app_client_id_here'
your_app_client_secret = 'put_your_app_client_secret_here'

m = Marker(your_app_client_id, your_app_client_secret)

Expand Down
8 changes: 5 additions & 3 deletions python/mental_command_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,11 @@ def on_inform_error(self, *args, **kwargs):

def main():

# Please fill your application clientId and clientSecret before running script
your_app_client_id = ''
your_app_client_secret = ''
# Enter your application Client ID and Client Secret below.
# You can obtain these credentials after registering your App ID with the Cortex SDK for development.
# For instructions, visit: https://emotiv.gitbook.io/cortex-api#create-a-cortex-app
your_app_client_id = 'put_your_app_client_id_here'
your_app_client_secret = 'put_your_app_client_secret_here'

# Init Train
t=Train(your_app_client_id, your_app_client_secret)
Expand Down
205 changes: 205 additions & 0 deletions python/query_records.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
from cortex import Cortex

class Records():
"""
A class to query records, request to download undownloaded records, and export local records

Attributes
----------
c : Cortex
Cortex communicate with Emotiv Cortex Service

Methods
-------
start():
start authorize process.
query_records():
To query records owned by the current user
request_download_records()
To request to download records if they are not at local machine
export_record()
To export records to CSV/ EDF files
"""
def __init__(self, app_client_id, app_client_secret, **kwargs):
"""
Constructs cortex client and bind a function to query records, request to download and export records
If you do not want to log request and response message , set debug_mode = False. The default is True
"""
print("Query Records __init__")
self.c = Cortex(app_client_id, app_client_secret, debug_mode=True, **kwargs)
self.c.bind(authorize_done=self.on_authorize_done)
self.c.bind(query_records_done=self.on_query_records_done)
self.c.bind(export_record_done=self.on_export_record_done)
self.c.bind(request_download_records_done=self.on_request_download_records_done)
self.c.bind(inform_error=self.on_inform_error)

def start(self):
"""
To open websocket and process authorizing step.
After get authorize_done The program will query records
Returns
-------
None
"""
self.c.open()

def query_records(self, license_id, application_id):
"""
To query records
Parameters
----------
orderBy : array of object, required : Specify how to sort the records.
query: object, required: An object to filter the records.
If you set an empty object, it will return all records created by your application
If you want get records created by other application, you need set licenseId and applicationId as parameter of query object
More detail at https://emotiv.gitbook.io/cortex-api/records/queryrecords
Returns
-------
"""

query_obj = {}
if license_id != '':
query_obj["licenseId"] = license_id
if application_id != '':
query_obj["applicationId"] = application_id

query_params = {
"orderBy": [{ "startDatetime": "DESC" }],
"query": query_obj,
"includeSyncStatusInfo":True
}
self.c.query_records(query_params)

def request_download_records(self, record_ids):
"""
To request to download records
Parameters
----------
record_ids : list, required: list of wanted record ids
More detail at https://emotiv.gitbook.io/cortex-api/records/requesttodownloadrecorddata
Returns
-------
None
"""
self.c.request_download_records(record_ids)

def export_record(self, record_ids, license_ids):
"""
To export records
By default, you can only export the records that were created by your application.
If you want to export a record that was created by another applications
then you must provide the license ids of those applications in the parameter licenseIds.
Parameters
record_ids: list, required: list of wanted export record ids
license_ids: list, no required: list of license id of other applications
----------
More detail at https://emotiv.gitbook.io/cortex-api/records/exportrecord
Returns
-------
None
"""
folder = '' # your place to export, you should have write permission, for example: 'C:\\Users\\NTT\\Desktop'
stream_types = ['EEG', 'MOTION', 'PM', 'BP']
export_format = 'CSV' # support 'CSV' or 'EDF'
version = 'V2'
self.c.export_record(folder, stream_types, export_format, record_ids, version, licenseIds=license_ids)


# callbacks functions
def on_authorize_done(self, *args, **kwargs):
print('on_authorize_done')
# query records
self.query_records(self.license_id, self.application_id)

# callbacks functions
def on_query_records_done(self, *args, **kwargs):
data = kwargs.get('data')
count = kwargs.get('count')
print('on_query_records_done: total records are {0}'.format(count))
# print(data)
not_downloaded_record_Ids = []
export_record_Ids = []
license_ids = []
for item in data:
uuid = item['uuid']
sync_status = item["syncStatus"]["status"]
application_id = item["applicationId"]
license_id = item["licenseId"]
print("recordId {0}, applicationId {1}, sync status {2}".format(uuid, application_id, sync_status))
if (sync_status == "notDownloaded") :
not_downloaded_record_Ids.append(uuid)
elif (sync_status == "neverUploaded") or (sync_status == "downloaded"):
export_record_Ids.append(uuid)
if license_id not in license_ids:
license_ids.append(license_id)

# download records has not downloaded to local machine
if len(not_downloaded_record_Ids) > 0:
self.request_download_records(not_downloaded_record_Ids)

# Open comment below to export records
# if len(export_record_Ids) > 0: # or export records are in local machine
# self.export_record(export_record_Ids, license_ids)

def on_export_record_done(self, *args, **kwargs):
print('on_export_record_done: the successful record exporting as below:')
data = kwargs.get('data')
print(data)
self.c.close()

def on_request_download_records_done(self, *args, **kwargs):
data = kwargs.get('data')
success_records = []
for item in data['success']:
record_Id = item['recordId']
print('The record '+ record_Id + ' is downloaded successfully.')
success_records.append(record_Id)

for item in data['failure']:
record_Id = item['recordId']
failed_msg = item['message']
print('The record '+ record_Id + ' is downloaded unsuccessfully. Because: ' + failed_msg)

self.c.close()

def on_inform_error(self, *args, **kwargs):
error_data = kwargs.get('error_data')
print(error_data)

# -----------------------------------------------------------
#
# GETTING STARTED
# - Please reference to https://emotiv.gitbook.io/cortex-api/ first.
# - Please make sure the your_app_client_id and your_app_client_secret are set before starting running.
# RESULT
# - on_query_records_done: will show all records filtered by query condition in query_record
# - on_export_record_done: will show the successful exported record
# - on_request_download_records_done: will show all success and failure download case
#
# -----------------------------------------------------------

def main():

# Enter your application Client ID and Client Secret below.
# You can obtain these credentials after registering your App ID with the Cortex SDK for development.
# For instructions, visit: https://emotiv.gitbook.io/cortex-api#create-a-cortex-app
your_app_client_id = 'put_your_app_client_id_here'
your_app_client_secret = 'put_your_app_client_secret_here'

# Don't need to create session in this case
r = Records(your_app_client_id, your_app_client_secret, auto_create_session= False)

# As default, the Program will query records of your application.
# In the case, you want to query records created from other application (such as EmotivPRO).
# You need set license_id and application_id of the application
# If set license_id without application_id. It will return records created from all applications use the license_id
# If set both license_id and application_id. It will return records from the application has the application_id
r.license_id = ''
r.application_id = ''

r.start()

if __name__ =='__main__':
main()

# -----------------------------------------------------------
9 changes: 5 additions & 4 deletions python/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ def on_inform_error(self, *args, **kwargs):
# - Please reference to https://emotiv.gitbook.io/cortex-api/ first.
# - Connect your headset with dongle or bluetooth. You can see the headset via Emotiv Launcher
# - Please make sure the your_app_client_id and your_app_client_secret are set before starting running.
# - In the case you borrow license from others, you need to add license = "xxx-yyy-zzz" as init parameter
# - Check the on_create_session_done() to see how to create a record.
# - Check the on_warn_cortex_stop_all_sub() to see how to export record
# RESULT
Expand All @@ -147,9 +146,11 @@ def on_inform_error(self, *args, **kwargs):

def main():

# Please fill your application clientId and clientSecret before running script
your_app_client_id = ''
your_app_client_secret = ''
# Enter your application Client ID and Client Secret below.
# You can obtain these credentials after registering your App ID with the Cortex SDK for development.
# For instructions, visit: https://emotiv.gitbook.io/cortex-api#create-a-cortex-app
your_app_client_id = 'put_your_app_client_id_here'
your_app_client_secret = 'put_your_app_client_secret_here'

r = Record(your_app_client_id, your_app_client_secret)

Expand Down
9 changes: 5 additions & 4 deletions python/sub_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ def on_inform_error(self, *args, **kwargs):
# - Please reference to https://emotiv.gitbook.io/cortex-api/ first.
# - Connect your headset with dongle or bluetooth. You can see the headset via Emotiv Launcher
# - Please make sure the your_app_client_id and your_app_client_secret are set before starting running.
# - In the case you borrow license from others, you need to add license = "xxx-yyy-zzz" as init parameter
# RESULT
# - the data labels will be retrieved at on_new_data_labels
# - the data will be retreived at on_new_[dataStream]_data
Expand All @@ -226,9 +225,11 @@ def on_inform_error(self, *args, **kwargs):

def main():

# Please fill your application clientId and clientSecret before running script
your_app_client_id = ''
your_app_client_secret = ''
# Enter your application Client ID and Client Secret below.
# You can obtain these credentials after registering your App ID with the Cortex SDK for development.
# For instructions, visit: https://emotiv.gitbook.io/cortex-api#create-a-cortex-app
your_app_client_id = 'put_your_app_client_id_here'
your_app_client_secret = 'put_your_app_client_secret_here'

s = Subcribe(your_app_client_id, your_app_client_secret)

Expand Down
24 changes: 15 additions & 9 deletions unity/Assets/Plugins/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@
/// </summary>
public static class AppConfig
{
public static string AppVersion = "1.1.0";
public static string AppName = "UnityApp";
public static string ClientId = "put_your_client_id_here";
public static string ClientSecret = "put_your_client_secret_here";
public static bool IsDataBufferUsing = false; // Set false if you want to display data directly to MessageLog without storing in Data Buffer
public static bool AllowSaveLogToFile = false; // Set true to save log to file and cortex token to local file for next time use

/*
* Enter your application Client ID and Client Secret below.
* You can obtain these credentials after registering your App ID with the Cortex SDK for development.
* For instructions, visit: https://emotiv.gitbook.io/cortex-api#create-a-cortex-app
*/
public static string ClientId = "put_your_client_id_here";
public static string ClientSecret = "put_your_client_secret_here";

public static string AppVersion = "1.1.0";
public static string AppName = "UnityApp";
public static bool IsDataBufferUsing = false; // Set false if you want to display data directly to MessageLog without storing in Data Buffer
public static bool AllowSaveLogToFile = false; // Set true to save log to file and cortex token to local file for next time use

#if !USE_EMBEDDED_LIB && !UNITY_ANDROID && !UNITY_IOS
// only for desktop without embedded cortex
public static string AppUrl = "wss://localhost:6868"; // for desktop without embedded cortex
public static string AppUrl = "wss://localhost:6868"; // for desktop without embedded cortex
#else
public static string AppUrl = ""; // Don't need AppUrl for mobile and embedded cortex
public static string AppUrl = ""; // Don't need AppUrl for mobile and embedded cortex
#endif

}
Loading
Loading