-
Notifications
You must be signed in to change notification settings - Fork 1
/
EEG_Main.py
103 lines (89 loc) · 2.52 KB
/
EEG_Main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#Run this code on the computer which is running the Emotiv Cortex app.
import json
from websocket import create_connection
import ssl
import time
import requests
ws = create_connection("wss://localhost:6868", sslopt={"cert_reqs": ssl.CERT_NONE})
#Approve app
ws.send(json.dumps({
"id": 1,
"jsonrpc": "2.0",
"method": "requestAccess",
"params": {
"clientId": "xxx", # The client id of your Cortex application
"clientSecret": "xxx" # The client secret of your Cortex application
}
}))
result = ws.recv()
result_dic = json.loads(result)
#Authorise and generate token
ws.send(json.dumps({
"id": 4,
"jsonrpc": "2.0",
"method": "authorize",
"params": {
"clientId": "xxx", # The client id of your Cortex application
"clientSecret": "xxx", # The client secret of your Cortex application
}
}))
result = ws.recv()
result_dic = json.loads(result)
auth = result_dic['result']['cortexToken']
print("---------------------- >Authorised")
#Create session
ws.send(json.dumps({
"id": 1,
"jsonrpc": "2.0",
"method": "createSession",
"params": {
"cortexToken": auth,
"headset": "INSIGHT-XXXXXXXX",
"status": "active"
}
}))
result = ws.recv()
result_dic = json.loads(result)
print('create session result ', json.dumps(result_dic, indent=4))
session_id = result_dic['result']['id']
#Load profile form cortexApp
ws.send(json.dumps({
"id": 1,
"jsonrpc": "2.0",
"method": "setupProfile",
"params": {
"cortexToken": auth,
"headset": "INSIGHT-XXXXXXXX",
"profile": "rovereeg",
"status": "load"
}
}))
print(ws.recv())
#stream data from device
ws.send(json.dumps({
"id": 1,
"jsonrpc": "2.0",
"method": "subscribe",
"params": {
"cortexToken": auth,
"session": session_id,
"streams": ["com"]
}
}))
print('\n')
print(ws.recv())
while True:
mental_command = json.loads(ws.recv())["com"][0]
print(mental_command)
if(thought == 'push'):
url_get = 'http://192.168.43.198:5000/forward' # Use the ip address of the raspberry pi board.
res = requests.get(url_get)
elif(thought == 'left'):
url_get = 'http://192.168.43.198:5000/pivot_left'
res = requests.get(url_get)
elif(thought == 'right'):
url_get = 'http://192.168.43.198:5000/pivot_right'
res = requests.get(url_get)
elif(thought == 'neutral'):
url_get = 'http://192.168.43.198:5000/stop_rover'
res = requests.get(url_get)