OSC streaming with Python-OSC

antonello
Posts: 4
Joined: Tue Jan 14, 2020 2:43 am

OSC streaming with Python-OSC

Post 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()
User avatar
James
Site Admin
Posts: 1089
Joined: Wed Jan 02, 2013 9:06 pm

Re: OSC streaming with Python-OSC

Post by James »

Try changing the IP to localhost (127.0.0.1) and turning off your firewall.
antonello
Posts: 4
Joined: Tue Jan 14, 2020 2:43 am

Re: OSC streaming with Python-OSC

Post 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 :)
User avatar
James
Site Admin
Posts: 1089
Joined: Wed Jan 02, 2013 9:06 pm

Re: OSC streaming with Python-OSC

Post 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!
BoyNeedsHelp
Posts: 9
Joined: Mon Mar 09, 2020 3:54 pm

Re: OSC streaming with Python-OSC

Post 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
User avatar
James
Site Admin
Posts: 1089
Joined: Wed Jan 02, 2013 9:06 pm

Re: OSC streaming with Python-OSC

Post 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.
BoyNeedsHelp
Posts: 9
Joined: Mon Mar 09, 2020 3:54 pm

Re: OSC streaming with Python-OSC

Post 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
User avatar
James
Site Admin
Posts: 1089
Joined: Wed Jan 02, 2013 9:06 pm

Re: OSC streaming with Python-OSC

Post by James »

The error is with the arguments, so what command line arguments are you typing in to run it?
BoyNeedsHelp
Posts: 9
Joined: Mon Mar 09, 2020 3:54 pm

Re: OSC streaming with Python-OSC

Post by BoyNeedsHelp »

None, at the moment I've just got a jupyter notebook running
User avatar
James
Site Admin
Posts: 1089
Joined: Wed Jan 02, 2013 9:06 pm

Re: OSC streaming with Python-OSC

Post 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.
Post Reply