Page 1 of 5

OSC streaming with Python-OSC

Posted: Tue Jan 14, 2020 2:52 am
by antonello
Hi,
has anyone manage to receive some data with python-osc module?

I'm using this simple server example but it doesn't work. Any help or thoughts would be really appreciated ;)

Code: Select all

import argparse

from pythonosc import dispatcher
from pythonosc import osc_server

def eeg_handler(unused_addr,args,ch1,ch2,ch3,ch4):
    print("EEG per channel: ",ch1,ch2,ch3,ch4)
    

if __name__ == '__main__':
    Port = 5000
    parser = argparse.ArgumentParser()
    parser.add_argument("--ip",default = "192.168.123.100")
    parser.add_argument("--port",default = Port)
    args = parser.parse_args()
    
    dispatcher = dispatcher.Dispatcher()
    dispatcher.map("/debug",print)
    dispatcher.map("/Muse/eeg",eeg_handler,"EEG")
    
    server = osc_server.ThreadingOSCUDPServer((args.ip,args.port), dispatcher)
    server.serve_forever()

Re: OSC streaming with Python-OSC

Posted: Tue Jan 14, 2020 8:39 am
by James
Try changing the IP to localhost (127.0.0.1) and turning off your firewall.

Re: OSC streaming with Python-OSC

Posted: Mon Jan 20, 2020 11:49 am
by antonello
Hi James,
I managed to do it. Thanks a lot for the help!!
What I would like to do now is stream to a single computer ~10 Muse and make some EEG processing based on blink detection.
So the setup would be 10 Muse->10 Mind Monitor -> 1 PC. All the phones and the PC will be connected to a dedicated router.
Do you see any kind of issues that I am not considering (Bandwith problem, high cpu usage, etc..).
Is there the possibility in your app to select a muse based on the name? If not, this could be a nice feature to add to your wonderful app.

Thanks in advance :)

Re: OSC streaming with Python-OSC

Posted: Mon Jan 20, 2020 12:01 pm
by James
This will work fine.
You can change the OSC prefix if you want in settings so you know which is which, or just stream to a different port for each instance.

If you want to control which Muse connects to which phone, you'll have to turn them on in order. I don't want to add a user interface element which could potentially cause connection issues for the 99% of users who will only have one Muse, sorry!

Re: OSC streaming with Python-OSC

Posted: Mon Mar 09, 2020 5:29 pm
by BoyNeedsHelp
James wrote: Tue Jan 14, 2020 8:39 am Try changing the IP to localhost (127.0.0.1) and turning off your firewall.
HI i've tried to do the same thing, but I keep getting the following error. Could you please help me out?

usage: ipykernel_launcher.py [-h] [--ip IP] [--port PORT]
ipykernel_launcher.py: error: unrecognized arguments: -f /Users/crecmarketing/Library/Jupyter/runtime/kernel-2df04bd3-b53e-4a3f-a9f1-781736834fbd.json

Re: OSC streaming with Python-OSC

Posted: Mon Mar 09, 2020 5:45 pm
by James
I'm not sure what "ipykernel_launcher.py" is and you've posted this reply twice in two different threads, neither of which mention this script, so I'm a little confused.

Re: OSC streaming with Python-OSC

Posted: Mon Mar 09, 2020 5:55 pm
by BoyNeedsHelp
James wrote: Mon Mar 09, 2020 5:45 pm I'm not sure what "ipykernel_launcher.py" is and you've posted this reply twice in two different threads, neither of which mention this script, so I'm a little confused.
Yeah, my bad. This is all very new to me, so I am not sure how to go about getting help with this.
The script is the same simple server example antonello used:

import argparse

from pythonosc import dispatcher
from pythonosc import osc_server

def eeg_handler(unused_addr,args,ch1,ch2,ch3,ch4):
print("EEG per channel: ",ch1,ch2,ch3,ch4)


if __name__ == '__main__':
Port = 5000
parser = argparse.ArgumentParser()
parser.add_argument("--ip",default = "127.0.0.1")
parser.add_argument("--port",default = Port)
args = parser.parse_args()

dispatcher = dispatcher.Dispatcher()
dispatcher.map("/debug",print)
dispatcher.map("/Muse/eeg",eeg_handler,"EEG")

server = osc_server.ThreadingOSCUDPServer((args.ip,args.port), dispatcher)
server.serve_forever();

from what I've read, the error is related the parser argument. I don't know how to get around this

Re: OSC streaming with Python-OSC

Posted: Mon Mar 09, 2020 5:57 pm
by James
The error is with the arguments, so what command line arguments are you typing in to run it?

Re: OSC streaming with Python-OSC

Posted: Mon Mar 09, 2020 6:00 pm
by BoyNeedsHelp
None, at the moment I've just got a jupyter notebook running

Re: OSC streaming with Python-OSC

Posted: Mon Mar 09, 2020 6:05 pm
by James
This script needs command line arguments, so you need to run it from a command prompt and supply the arguments.

I've not used jupyter notebook, but Googling it looks like some kind of web based thing. That's unlikely to work with this as the OSC data needs to coe in over a UDP network connection and that's not something that web browsers usually support. .. but I've not used it, so maybe it's ok.