Mind Monitor Python OSC Examples

warmcupoftea
Posts: 5
Joined: Thu Jul 15, 2021 11:49 am

Re: Mind Monitor Python OSC Examples

Post by warmcupoftea »

James wrote: Fri Jul 16, 2021 11:48 am The MatPlotLib library is not thread safe. It works fine on Windows, but not on linux/mac, so there's a bug in there they need to fix.
https://matplotlib.org/stable/faq/howto ... th-threads

This is only used in the plotting audio feedback example.
Yes, I realized that the audio feedback example is the only one that has visual graphics. I'm making sure with you if this is correct. Thanks for the URL link! And yes, I found many issues inform about this MatPlotLin bug with macOS. Seems like that's going to take some time for me to find a solution.
James wrote: Fri Jul 16, 2021 11:48 am
If you're getting threading errors with the simple examples, then I'm not sure what's wrong sorry. I'd do a new clean install of the latest version of python.

I don't have linux/mac, so I'm not sure what you mean by xcode being an issue. I don't think xcode should affect pyton, but like I said, I don't run a mac, so I'm not sure, sorry.
Oh.. that is just information I'd like to update here in the case that someone works on Mac Catalina and facing the same issue. If they can't run python3 although has it installed already, which is what runs your code. They might want to check their Xcode version. [https://stackoverflow.com/questions/525 ... veloper-pa] Also, check their pip and pip3 as well. They might need "pip3 install python-osc" not regular pip.
James wrote: Fri Jul 16, 2021 11:48 am The data in the second screenshot is good. You've got the date/time followed by RAW EEG values from TP9, AF7, AF8, TP10 and AUXR.
Thank you very much for confirming this. :-) !!!
banjo
Posts: 17
Joined: Sat Feb 05, 2022 4:10 pm

Re: Mind Monitor Python OSC Examples

Post by banjo »

I have Win10 and when running "OSC Receiver Audio Feedback.py" I get below error message, the program runs until I end it, but nothing is shown.
I have Python 3.6.3, verified that matplotlib, python-osc, and playsound got installed. The error obviously points to Matplotlib and/or threading.
What might be the reason and how to fix it?

Code: Select all

Listening on UDP port 5000
c:\Users\thanh\Documents\Muse\OSC Receiver Audio Feedback.py:118: UserWarning: Starting a Matplotlib GUI outside of the main thread will likely fail.
  ani = FuncAnimation(plt.gcf(), plot_update, interval=100)
WARNING: QApplication was not created in the main() thread.
c:\Users\thanh\Documents\Muse\OSC Receiver Audio Feedback.py:120: UserWarning: Starting a Matplotlib GUI outside of the main thread will likely fail.
  plt.show()
Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\threading.py", line 916, in _bootstrap_inner
    self.run()
  File "C:\Program Files\Python36\lib\threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "c:\Users\thanh\Documents\Muse\OSC Receiver Audio Feedback.py", line 120, in init_plot
    plt.show()
  File "C:\Program Files\Python36\lib\site-packages\matplotlib\pyplot.py", line 353, in show
    return _backend_mod.show(*args, **kwargs)
  File "C:\Program Files\Python36\lib\site-packages\matplotlib\backend_bases.py", line 3544, in show
    cls.mainloop()
  File "C:\Program Files\Python36\lib\site-packages\matplotlib\backends\backend_qt5.py", line 1037, in mainloop
    signal.signal(signal.SIGINT, signal.SIG_DFL)
  File "C:\Program Files\Python36\lib\signal.py", line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread
User avatar
James
Site Admin
Posts: 1109
Joined: Wed Jan 02, 2013 9:06 pm

Re: Mind Monitor Python OSC Examples

Post by James »

It's a threading warning. The code works fine on Windows, so you can just ignore the warning.
If you're not seeing data, check your firewall is open and that you've got the right target IP set in Mind Monitor's settings.
Also try running the simple example to see if that works.
banjo
Posts: 17
Joined: Sat Feb 05, 2022 4:10 pm

Re: Mind Monitor Python OSC Examples

Post by banjo »

Thx, not seeing data, but not even seeing the window where the data should be shown. Or will that window show up first when data is received?
Have also tried "OSC Receiver", but it isn't receiving the Marker presses I do. In Mind Monitor I have the Target IP same as my computer's IP, and the OSC Stream port is 5000.
In my firewall I have allowed port 5000.
Don't know what setting is amiss.
User avatar
James
Site Admin
Posts: 1109
Joined: Wed Jan 02, 2013 9:06 pm

Re: Mind Monitor Python OSC Examples

Post by James »

Make sure you allow UDP 5000, not TCP 5000.
Data will show in the window as soon as it's received. If you're not seeing the data, then you're not running it correctly, or something is blocking the network traffic.
Don't forget to press the stream button on Mind Monitor to start sending data.
banjo
Posts: 17
Joined: Sat Feb 05, 2022 4:10 pm

Re: Mind Monitor Python OSC Examples

Post by banjo »

Yes, UDP 5000 is allowed in the firewall (Windows Defender), and streaming is started from Mind Monitor. Guess something is blocking the traffic, don't have a clue where it could be.
I understand data will show in the window when it's received, but I don't even see the graphical window waiting for data. The program is running but nothing is visible apart from the terminal window, when I start it ("OSC Receiver Audio Feedback.py") something is quickly flashing in the Windows taskbar, but it disappears right away. Guess this is the graphical window that should be shown.
Not sure if I have one or two issues: 1 Data not received (due to some network issues), 2 Graphical window not shown?

PS After midnight here now, so will go to sleep now :)
User avatar
James
Site Admin
Posts: 1109
Joined: Wed Jan 02, 2013 9:06 pm

Re: Mind Monitor Python OSC Examples

Post by James »

Run the python from the command line, don't just double click the file in windows.
banjo
Posts: 17
Joined: Sat Feb 05, 2022 4:10 pm

Re: Mind Monitor Python OSC Examples

Post by banjo »

James wrote: Sat Feb 05, 2022 5:10 pm Run the python from the command line, don't just double click the file in windows.
Yes, that's what I've been doing, have also tried it from MS Visual Studio Code. As said, the Python program is running, but the Matplotlib window is not shown, or if it is, then just for half a second before closing. Will now search for another program using Matplotlib to see if that's the culprit.
Edit: Found a random Python program using Matplotlib, it is working ok.

The network issue I don't know how to troubleshoot, how can I know if my phone (iPhone with iOs 15.3) really is transmitting? In the settings for Privacy /Local network, Mind Monitor is allowed. Is Wireshark (or similar tool) the only option to check this?
On my laptop I use IPCONFIG to find this: "IPv4 Address. . .. . . . : 192.168.178.159", this is the target address I put in Mind Monitor, guess that's correct?
As my phone and laptop obviously are in the same local network, I shouldn't need to change anything on my Internet modem/router, correct? Only open UDP 5000 in the laptop's firewall settings, like I've done.
Edit: Took a plunge and installed Wireshark, data is indeed flowing from my phone towards my computer, can see Muse related data in the Wireshark feed. Don't know how to check if data really is received by my computer, it is anyhow not received by the Python programs.

I'm confident the root cause for my problems is not on Mind Monitor's side, but glad for any help I can get. Would love to be able to use Python for receiving EEG signals from Muse.

Added one piece of data received on my computer as captured by Wireshark:

27776 74.338973 192.168.178.98 192.168.178.159 UDP 122 65412 → 5000 Len=80

0000 bc 83 85 23 50 78 a6 f6 cc 52 d6 0a 08 00 45 00 ...#Px...R....E.
0010 00 6c ba 63 00 00 40 11 d9 ca c0 a8 b2 62 c0 a8 .l.c..@......b..
0020 b2 9f ff 84 13 88 00 58 1c 98 23 62 75 6e 64 6c .......X..#bundl
0030 65 00 e5 aa 17 eb 0c 84 90 00 00 00 00 3c 2f 54 e............</T
0040 59 2f 6d 75 73 65 2f 65 6c 65 6d 65 6e 74 73 2f Y/muse/elements/
0050 64 65 6c 74 61 5f 61 62 73 6f 6c 75 74 65 00 00 delta_absolute..
0060 00 00 2c 66 66 66 66 00 00 00 bf 24 5a b0 be 40 ..,ffff....$Z..@
0070 f4 68 3f 48 3f 0c bf 0f ad e9 .h?H?.....
banjo
Posts: 17
Joined: Sat Feb 05, 2022 4:10 pm

Re: Mind Monitor Python OSC Examples

Post by banjo »

I believe Python as such can receive UDP data on my computer.

This type of data:

Code: Select all

received message: b'#bundle\x00\xe5\xaa!J\xd1\n \x00\x00\x00\x00,/TY/muse/eeg\x00\x00\x00\x00,fffff\x00\x00DW*3DUZ\x06DV[\xe6DT$\x92DV\xc3\x0c'
was received when streaming from Mind Monitor with the code below. Data is received only when streaming from Mind Monitor.
So something amiss with Python Osc in my installation?

Code: Select all

import socket

UDP_IP = "0.0.0.0"
UDP_PORT = 5000

sock = socket.socket(socket.AF_INET, # Internet
                     socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))

while True:
    data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
    print("received message: %s" % data)
User avatar
James
Site Admin
Posts: 1109
Joined: Wed Jan 02, 2013 9:06 pm

Re: Mind Monitor Python OSC Examples

Post by James »

Yeah, looks like it. Sorry, I've no idea on that one.
I take it you get the same failure when running the simple receiver example?
Post Reply