OSC streaming with Python-OSC

User avatar
James
Site Admin
Posts: 1110
Joined: Wed Jan 02, 2013 9:06 pm

Re: OSC streaming with Python-OSC

Post by James »

127.0.0.1 is local loopback. It won't work over network. You need to send to you actual local IP which will likely start with 192.168.something.something, or 10.10.something.something.
Find you local IP on windows with the command line "ipconfig".
ALarini
Posts: 5
Joined: Thu Dec 09, 2021 1:59 pm

Re: OSC streaming with Python-OSC

Post by ALarini »

That's exactly the kind of basic thing I think I'm missing. As 127.0.0.1 worked for Lab, I thought it was ok.

Anyway I've tried with my IPv4 Address, 192.168.x.x, sending there from Muse Direct, as well as then trying to bridge through Muse Lab, and listening on the same IP and port of course with my OSC server, and the result has been exactly the same...

Maybe as my code is simply the script in a PyCharm project, I need to do something more to have it receiving from any client outside that same project?
Pasting here my actual code:

Code: Select all

import argparse
from pythonosc import dispatcher
from pythonosc import osc_server


def testmuse(unused_addr, *args):
    print(args)


def testmuse_d(unused_addr, *args):
    print('default', args)


def start_server(ip, port):
    print("Starting Server")
    server = osc_server.ThreadingOSCUDPServer((ip, port), dispatcher)
    print("Serving on {}".format(server.server_address))
    server.serve_forever()


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--serverip", default="192.168.43.243", help="The ip to listen on")
    parser.add_argument("--serverport", type=int, default=7002, help="The port the OSC Server is listening on")
    args = parser.parse_args()

    # listen to addresses and print changes in values
    dispatcher = dispatcher.Dispatcher()

    dispatcher.map("/Person0/*", testmuse)
    dispatcher.set_default_handler(testmuse_d)

    start_server(args.serverip, args.serverport)
User avatar
James
Site Admin
Posts: 1110
Joined: Wed Jan 02, 2013 9:06 pm

Re: OSC streaming with Python-OSC

Post by James »

Have you tried with the code samples in my GitHub, linked in the FAQ/OSC section?
ALarini
Posts: 5
Joined: Thu Dec 09, 2021 1:59 pm

Re: OSC streaming with Python-OSC

Post by ALarini »

I've tried everything shared on this topic but I don't know about those. I've tried now to check the FAQ section here but I see only "forum FAQ", nothing about osc
User avatar
James
Site Admin
Posts: 1110
Joined: Wed Jan 02, 2013 9:06 pm

Re: OSC streaming with Python-OSC

Post by James »

ALarini
Posts: 5
Joined: Thu Dec 09, 2021 1:59 pm

Re: OSC streaming with Python-OSC

Post by ALarini »

Thanks. Then yes, the simple one to start with. I've re-tried it now to be sure.

Code: Select all

"""
Mind Monitor - Minimal EEG OSC Receiver
Coded: James Clutterbuck (2021)
Requires: pip install python-osc
"""
from datetime import datetime
from pythonosc import dispatcher
from pythonosc import osc_server

ip = "192.168.**.*** "
port = 5000


def eeg_handler(address: str, *args):
    dateTimeObj = datetime.now()
    printStr = dateTimeObj.strftime("%Y-%m-%d %H:%M:%S.%f")
    for arg in args:
        printStr += "," + str(arg)
    print(printStr)


def default_handler():
    print ('default')


if __name__ == "__main__":
    dispatcher = dispatcher.Dispatcher()
    dispatcher.map("/muse/eeg", eeg_handler)
    dispatcher.map("/Person0/*", eeg_handler)
    dispatcher.map("/*", eeg_handler)
    dispatcher.set_default_handler(default_handler)

    server = osc_server.ThreadingOSCUDPServer((ip, port), dispatcher)
    print("Listening on ip", ip, "UDP port " + str(port))
    server.serve_forever()
I've tried with ip "0.0.0.0" as in github, then 127*** and then 192***, same result: everything seems to work but nothing is printed, seems like no handler is being called.
One thing, when I stop the server by stopping the process in PyCharm, I do receive some kind of error, but I guess they don't matter. Copying here anyway:

Code: Select all

Traceback (most recent call last):
  File "C:/Users/Alex Larini/PycharmProjects/Muse-osc3/Muse_osc.py", line 35, in <module>
    server.serve_forever()
  File "C:\Users\Alex Larini\AppData\Local\Programs\Python\Python38\lib\socketserver.py", line 232, in serve_forever
    ready = selector.select(poll_interval)
  File "C:\Users\Alex Larini\AppData\Local\Programs\Python\Python38\lib\selectors.py", line 323, in select
    r, w, _ = self._select(self._readers, self._writers, [], timeout)
  File "C:\Users\Alex Larini\AppData\Local\Programs\Python\Python38\lib\selectors.py", line 314, in _select
    r, w, x = select.select(r, w, w, timeout)
KeyboardInterrupt

Process finished with exit code -1073741510 (0xC000013A: interrupted by Ctrl+C)
User avatar
James
Site Admin
Posts: 1110
Joined: Wed Jan 02, 2013 9:06 pm

Re: OSC streaming with Python-OSC

Post by James »

I'm not sure sorry. Firewall?
ALarini
Posts: 5
Joined: Thu Dec 09, 2021 1:59 pm

Re: OSC streaming with Python-OSC

Post by ALarini »

Checked, Pycharm is allowed to everything, same for Muse Direct (Direct is sending properly anyway, Lab receives every package on the right port and correct address).
:(
banjo
Posts: 17
Joined: Sat Feb 05, 2022 4:10 pm

Re: OSC streaming with Python-OSC

Post by banjo »

Did you find any solution for this? I have same or at least similar problem, as written in another thread: viewtopic.php?p=3308#p3308


Edit: Found the reason for data not received properly, in the Mind Monitor settings I had "TY" in the OSC Path prefix. The other thread is updated with this info.
rachel.dale.eng
Posts: 1
Joined: Mon Jul 11, 2022 5:10 pm

Re: OSC streaming with Python-OSC

Post by rachel.dale.eng »

James wrote: Tue Jan 14, 2020 8:39 am Try changing the IP to localhost (127.0.0.1) and turning off your firewall.
Hey James, about your reply advising the IP change to localhost (127.0.0.1), may you please share why and how you thought about and advised this change?
Thank you!
Post Reply