Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api logging #4

Merged
merged 2 commits into from
May 1, 2024
Merged

Api logging #4

merged 2 commits into from
May 1, 2024

Conversation

vivian-dai
Copy link
Contributor

Setup steps

  1. download launcher
  2. log into the emotiv launcher. this is a background app that acts as a wss server
  3. need to use the emotiv launcher to accept access after running code for first time for setup

other files etc

Copy link
Collaborator

@LemonFace0309 LemonFace0309 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks great so far! Just some questions about how things work here

Comment on lines +20 to +22
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
localhost_pem = pathlib.Path(__file__).with_name("cert.pem")
ssl_context.load_verify_locations(localhost_pem)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you link to where in the documentation this was mentioned?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also add where in the documentation if mentions to include cert.pem?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that Cortex only supports the WebSocket Secure (wss) protocol. It doesn't support the plain WebSocket (ws) protocol without encryption.

The Cortex web socket server uses a self-signed certificate. When you install Emotiv softwares, the installer has already installed the Emotiv Root CA file and ask the system to trust it, so most of the time, your application don't need to configure anything else.

docs

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we passing in a cert.pem file if it's saying that it doesn't need it? Do you have reference to where you got this code from? Have you tried running this code without the cert.pem file and without the SSLContext?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think that means the launcher itself because the section after that is talking about using a raspberry pi as the wss server. it wasn't working without the cert.pem file

async with websockets.connect("wss://localhost:6868", ssl=ssl_context) as websocket:
# by default emotiv uses port 6868, uses wss protocol
# first need to request access
await send_message({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: but in the documentation they say to call getUserLogin to check if the user already logged in.

https://emotiv.gitbook.io/cortex-api/authentication

First, you should call [getUserLogin](https://emotiv.gitbook.io/cortex-api/authentication/getuserlogin) to check if the user has already logged in though [EMOTIV Launcher](https://emotiv.gitbook.io/emotiv-launcher/). Then, you must call [requestAccess](https://emotiv.gitbook.io/cortex-api/authentication/requestaccess) to ask the user to approve your application.

"status": "open"
}
}, websocket)
session_id = response["result"]["id"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does the value of session_id change? Will it be different every time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, after the script stops running the session is closed so a new session id needs to be generated on the next run

A session is linked to an application. All the sessions of an application are automatically closed when the application is disconnected from the Cortex service. A session is also closed if the headset is disconnected.
from docs

@@ -185,7 +342,7 @@ def run_experiment(trials, window, subj, session_number, n_images, all_images):

# Display break message at the end of each block
display_break_message(window, trial['block'])

await teardown_eeg()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we call this twice?

Copy link
Contributor Author

@vivian-dai vivian-dai Apr 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops, that was remenants from testing, i don't think it ever reached the call on line 421 when i was testing it but hopefully that's just because i was exiting the experiment early/no actual hardware

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no worries! Just remote it pls

Comment on lines +155 to +156
print(response)
# wait for warning 18
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is warning 18?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's for successfully saved record

You must stop the record before you can export it. If you want to export a record immediately after you stop it then you must wait for the warning 18 before you try to export.

from documentation

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha. Maybe link to the documentation and copy paste this:

The record data has been successfully saved. Cortex sends this warning when a record is done with some long-run post processing after record is stopped.

Copy link
Collaborator

@LemonFace0309 LemonFace0309 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice. Thanks for addressing the comments. Please make the changes here and in the main repo too.

Comment on lines +155 to +156
print(response)
# wait for warning 18
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha. Maybe link to the documentation and copy paste this:

The record data has been successfully saved. Cortex sends this warning when a record is done with some long-run post processing after record is stopped.

@@ -185,7 +342,7 @@ def run_experiment(trials, window, subj, session_number, n_images, all_images):

# Display break message at the end of each block
display_break_message(window, trial['block'])

await teardown_eeg()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no worries! Just remote it pls

@vivian-dai vivian-dai merged commit 007c03d into main May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants