Esempio n. 1
0
def main():
    print("Waiting for boot signal")
    print(s.read())
    print("Writing sway command")
    s.write("".join(map(chr, [0x55, 0x0, 0x3, 0, 2, 72])))
    print(s.read())
    # print("Reading motor encoders")
    # s.write("".join(map(chr, [0x55, 0x1, 0x12])))
    # print(["0x%.02x " % ord(x) for x in s.read(12)])
    server = OSCServer( ("192.168.123.75", 10000) )
    server.timeout = 0
    # funny python's way to add a method to an instance of a class
    import types
    server.handle_timeout = types.MethodType(handle_timeout, server)

    server.addMsgHandler( "/rotate", rotate_callback )
    server.addMsgHandler( "/bf", bf_callback )
    
    try:
        while 1:
            server.handle_request()
    except KeyboardInterrupt:
        pass


    server.close()
Esempio n. 2
0
def setupServer():
  global server
  server = OSCServer( (HOST_NAME, PORT_NUM) )
  server.timeout = 0
  server.handle_timeout = types.MethodType(handle_timeout, server)
  server.addMsgHandler( "/dmx", user_callback )
  print(server)
def main():
    global server
    
    connected = False

    while not connected:
        try:
            server = OSCServer( ("10.101.203.74", 10000) )
            server.timeout = 0
            run = True
            connected = True

        except: 
            print "OSC Server no encontrado"
            time.sleep(5)

    GPIO.setmode(GPIO.BCM)
    m = Motor([17,18,27,22])

    server.handle_timeout = types.MethodType(handle_timeout, server)

    server.addMsgHandler( "/base", base_move )
    server.addMsgHandler( "/altura", altura_move )

    while(True):
        each_frame()
        try:
            m.rpm = 10
            m.move_to(rotateBase)
            # m.move_to(0)

        except KeyboardInterrupt:
            GPIO.cleanup()   
            print "Saliendo..."
            exit()
Esempio n. 4
0
def main():
    print("Waiting for boot signal")
    print(s.read())
    print("Writing sway command")
    s.write("".join(map(chr, [0x55, 0x0, 0x3, 0, 2, 72]))) # equivalent to .join['U', '\x00', '\x03', '\x00', '\x02', 'H']
    # between every elements in the list, put ""
    # that will convert it as one string ''Ux00x03x00x02H''
    print(s.read())
    # print("Reading motor encoders")
    # s.write("".join(map(chr, [0x55, 0x1, 0x12])))
    # print(["0x%.02x " % ord(x) for x in s.read(12)])
    server = OSCServer( ("192.168.123.75", 10000) )
    server.timeout = 0
    # funny python's way to add a method to an instance of a class
    import types
    server.handle_timeout = types.MethodType(handle_timeout, server)

    server.addMsgHandler( "/rotate", rotate_callback )
    server.addMsgHandler( "/bf", bf_callback )
    
    try:
        while 1:
            server.handle_request()
    except KeyboardInterrupt:
        pass


    server.close()
Esempio n. 5
0
def server_start(port=7110):
    global server
    server = OSCServer(("localhost", 7110))
    server.timeout = 0

    server.handle_timeout = types.MethodType(handle_timeout, server)

    server.addMsgHandler("/sco", handle_score)
    server.addMsgHandler("/cc", handle_cc)
    server.addMsgHandler("/quit", quit_callback)
    server.addMsgHandler("default", default_callback)
Esempio n. 6
0
def server_start(port=7110):
    global server
    server = OSCServer ( ("localhost", 7110))
    server.timeout = 0

    server.handle_timeout = types.MethodType(handle_timeout, server)

    server.addMsgHandler("/sco", handle_score)
    server.addMsgHandler("/cc", handle_cc)
    server.addMsgHandler("/quit", quit_callback)
    server.addMsgHandler("default", default_callback)
Esempio n. 7
0
def main():

	if len(sys.argv)>1:
		OSC_ADDRESS = str(sys.argv[1])
	else:
		OSC_ADDRESS = OSC_ADDRESS_DEFAULT

	if len(sys.argv)>2:
		OSC_PORT = int(sys.argv[2])
	else:
		OSC_PORT = OSC_PORT_DEFAULT

	if len(sys.argv)>3:
		WIFI_INT = str(sys.argv[3])
	else:
		WIFI_INT = WIFI_INT_DEFAULT

	#creates directory to store sounds
	if not os.path.exists(sounddir):
		os.makedirs(sounddir)
	print("Sound directory: ",sounddir)

	#example of use of pyosc,
	#see: https://github.com/ptone/pyosc/blob/master/examples/knect-rcv.py
	#we use here the WiFi interface provided on device en0
	ipcmd = "ipconfig getifaddr %s"%WIFI_INT
	print(ipcmd)
	ipaddress = os.popen(ipcmd).read().rstrip()
	print("IP address: ",ipaddress)
	server = OSCServer((ipaddress, OSC_PORT))
	server.timeout = 0
	global run
	run = True

	print("Listening to OSC address",OSC_ADDRESS,"on port",OSC_PORT)

	#python's way to add a method to an instance of a class
	server.handle_timeout = types.MethodType(handle_timeout, server)

	server.addMsgHandler(OSC_ADDRESS, user_callback)

	#sound query engine
	try:
		while run:
			#sleep(1)
			#call user script
			each_frame(server)
	except KeyboardInterrupt: #to quit program
		print("\n")
		pass
	server.close()
Esempio n. 8
0
def frame(savePath):
    print 'getting osc'
    # funny python's way to add a method to an instance of a class
    server = OSCServer(("192.168.1.209", 12000))
    server.timeout = 0
    run = True
    server.handle_timeout = types.MethodType(handle_timeout, server)
    server.addMsgHandler("/acc", acc_callback)
    server.addMsgHandler("/e", eul_callback)
    server.addMsgHandler("/raw", raw_callback)
    while True:
        each_frame(server)
        #print 'hello'
        sleep(0.001)
    return
Esempio n. 9
0
def main(hostname="localhost",port="8000"):
    server = OSCServer((hostname, int(port)))
    server.timeout = 0
    run = True
    global message_count
    message_count = 0

    # this method of reporting timeouts only works by convention
    # that before calling handle_request() field .timed_out is 
    # set to False
    def handle_timeout(self):
        self.timed_out = True

    # funny python's way to add a method to an instance of a class
    import types
    server.handle_timeout = types.MethodType(handle_timeout, server)

    def user_callback(path, tags, args, source):
        log("%s %s\n" % (path, args))
        global message_count
        message_count += 1

    def quit_callback(path, tags, args, source):
        #global run
        run = False

    server.addMsgHandler( "default", user_callback )
    server.addMsgHandler( "/quit", quit_callback )

    # user script that's called by the game engine every frame
    def each_frame():
        log("Messages received: %s\n" % message_count)
        # clear timed_out flag
        server.timed_out = False
        # handle all pending requests then return
        while not server.timed_out:
            server.handle_request()

    # simulate a "game engine"
    print "Server running at %s:%s" % (hostname, port)
    while run:
        # do the game stuff:
        sleep(1)
        # call user script
        each_frame()

    server.close()
Esempio n. 10
0
def main(hostname="localhost", port="8000"):
    server = OSCServer((hostname, int(port)))
    server.timeout = 0
    run = True
    global message_count
    message_count = 0

    # this method of reporting timeouts only works by convention
    # that before calling handle_request() field .timed_out is
    # set to False
    def handle_timeout(self):
        self.timed_out = True

    # funny python's way to add a method to an instance of a class
    import types
    server.handle_timeout = types.MethodType(handle_timeout, server)

    def user_callback(path, tags, args, source):
        log("%s %s\n" % (path, args))
        global message_count
        message_count += 1

    def quit_callback(path, tags, args, source):
        #global run
        run = False

    server.addMsgHandler("default", user_callback)
    server.addMsgHandler("/quit", quit_callback)

    # user script that's called by the game engine every frame
    def each_frame():
        log("Messages received: %s\n" % message_count)
        # clear timed_out flag
        server.timed_out = False
        # handle all pending requests then return
        while not server.timed_out:
            server.handle_request()

    # simulate a "game engine"
    print "Server running at %s:%s" % (hostname, port)
    while run:
        # do the game stuff:
        sleep(1)
        # call user script
        each_frame()

    server.close()
# ip address finder
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
ifname = 'eth0'
localIP = socket.inet_ntoa(
    fcntl.ioctl(
        s.fileno(),
        0x8915,  # SIOCGIFADDR
        struct.pack('256s', ifname[:15]))[20:24])

clientAddress = '192.168.0.153', 9999
serverAddress = localIP, 9998

ser = Serial('/dev/ttyUSB0', 9600)

columnServer = OSCServer(serverAddress)
columnServer.timeout = 0
run = True

columnClient = OSCClient()
columnClient.connect(clientAddress)

# Audio player
pygame.mixer.init()
uniqueSound = pygame.mixer.Sound("testSound.wav")
uniqueSound.set_volume(0)
uniqueSound.play(-1)

pygame.mixer.music.load("testSound.wav")
pygame.mixer.music.set_volume(0)
#pygame.mixer.music.play(-1)
Esempio n. 12
0
import struct

# ip address finder
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
ifname = 'eth0'
localIP = socket.inet_ntoa(
    fcntl.ioctl(
        s.fileno(),
        0x8915,  # SIOCGIFADDR
        struct.pack('256s', ifname[:15]))[20:24])

clientAddress = '192.168.2.1', 9999
serverAddress = localIP, 9998

lockerServer = OSCServer(serverAddress)
lockerServer.timeout = 0
run = True

lockerClient = OSCClient()
lockerClient.connect(clientAddress)

# Create a default object, no changes to I2C address or frequency
locker = Adafruit_MotorHAT(addr=0x60)

totalPixels = 1000  # Number of LEDs in Locker
pixel = 0

# Control Pins for the Raspberry Pi to the Dot Star strip
datapin = 23
clockpin = 24
#strip	  = Adafruit_DotStar(totalPixels, datapin, clockpin)
Esempio n. 13
0
 
def debug_callback(path, tags, args, source):
    global SCRIPT
    print("Args from debug message: %s" % args)
    SCRIPT.update_osc(args)
    # conn = httplib.HTTPConnection("localhost:8833")
    # conn.request("GET", "/fromosc")

if __name__ == '__main__':
    myServer = gevent.pywsgi.WSGIServer(('0.0.0.0', 8833), app,
                             handler_class=geventwebsocket.handler.WebSocketHandler)
    serverThread = gevent.spawn(serve_forever, myServer);
    print("Started the wsgi server thread.")

    myOSCServer = OSCServer( ("localhost", 5006) )
    myOSCServer.timeout = 0
    myOSCServer.addMsgHandler( "/bcdata", debug_callback )
    oscServerThread = gevent.spawn(serve_forever, myOSCServer)
    print("Started the osc server thread.")

    gevent.joinall([serverThread, oscServerThread])

# WS = []
 
# def osc_listen(data):
#     global WS
#     # NOTE: We should catch errors here and create a new WS_NEW list for sockets that don't error, then swap them at the end
#     for ws in WS:
#         ws.send(data)
 
# if __name__ == '__main__':
Esempio n. 14
0
def step_impl(context, message):
    listen = OSCServer(("127.0.0.1", 4589))
    listen.timeout = 0 #infinite timeout
    listen.addMsgHandler("/err", listen_handler)
    listen.close()
Esempio n. 15
0
def remote_started_callback(path, tags, args, source):
  print "Player started", args
  # global running
  # running = True

def remote_files_callback(path, tags, args, source):
  print "Player has these files:", args


if __name__ == "__main__":
  try:
    sys.excepthook = log_uncaught_exceptions

    notifications = OSCServer( (args.notifierip, args.notifierport) )
    notifications.timeout = 0.1
    # funny python's way to add a method to an instance of a class
    notifications.handle_timeout = types.MethodType(handle_timeout, notifications)

    # RPi.GPIO Layout verwenden (wie Pin-Nummern)
    GPIO.setmode(GPIO.BOARD)

    for _button in button_map:
      GPIO.setup(_button, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # PUD_DOWN, because we use a pull down resistor, use RISING in next line then!
      GPIO.add_event_detect(_button, GPIO.RISING, callback=button_press, bouncetime=args.bouncetime)

    client.connect( (args.ip, args.port) )
    notifications.addMsgHandler( "/stopped", remote_stopped_callback )
    notifications.addMsgHandler( "/playing", remote_started_callback )
    notifications.addMsgHandler( "/files", remote_files_callback )
Esempio n. 16
0
    # don't do this at home (or it'll quit blender)
    global run
    run = False

# user script that's called by the game engine every frame
def each_frame(*args):
    while True:
        # clear timed_out flag
        server.timed_out = False
        # handle all pending requests then return
        if not server.timed_out:
            server.handle_request()
        time.sleep(0.001)

server = OSCServer( ("0.0.0.0", 6666) )
server.timeout = 0.001
run = True
server.handle_timeout = types.MethodType(handle_timeout, server)

server.addMsgHandler( "/m", user_callback )
server.addMsgHandler( "/s", user_callback )
#server.addMsgHandler( "/quit", quit_callback )

data = ""
sleeptime = 0.001

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.bind(("0.0.0.0", 6454))
sock.settimeout(0.001)

    #27 28 29 30 31 32 33 34 35 36 37 38 39 40 
Esempio n. 17
0
import sys
from time import sleep
from omxplayer import OMXPlayer  #https://github.com/willprice/python-omxplayer-wrapper

# BUTTON - to stop all PIs - send message to Master and Master to all Slaves
#http://razzpisampler.oreilly.com/ch07.html
import os

# https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=133665
from subprocess import call

# SET UP ...........................................................................................

server = OSCServer(
    ("0.0.0.0", 1111))  # "0.0.0.0" = local ip | port = 1111 (master)
server.timeout = 0  # waiting time to receive
run = True  # server is running

# SET UP video
# https://github.com/willprice/python-omxplayer-wrapper/issues/34
# --no-osd = no player on screen - https://github.com/KenT2/pipresents/issues/25

player = OMXPlayer("/home/pi/Videos/scene_01_05_nets.mp4",
                   args=['--no-osd', '--loop'])


# this method of reporting timeouts only works by convention
# that before calling handle_request() field .timed_out is
# set to False
def handle_timeout(self):
    self.timed_out = True
# ip address finder
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
ifname = 'eth0'
localIP = socket.inet_ntoa(fcntl.ioctl(
        s.fileno(),
        0x8915,  # SIOCGIFADDR
        struct.pack('256s', ifname[:15])
    )[20:24])

clientAddress = '192.168.0.153', 9999
serverAddress = localIP, 9998

ser = Serial('/dev/ttyUSB0', 9600)

columnServer = OSCServer( serverAddress ) 
columnServer.timeout = 0
run = True

columnClient = OSCClient()
columnClient.connect(clientAddress)

# Audio player
pygame.mixer.init()
uniqueSound = pygame.mixer.Sound("testSound.wav")
uniqueSound.set_volume(0)
uniqueSound.play(-1)

pygame.mixer.music.load("testSound.wav")
pygame.mixer.music.set_volume(0)
#pygame.mixer.music.play(-1)
Esempio n. 19
0
import struct

# ip address finder
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
ifname = 'eth0'
localIP = socket.inet_ntoa(fcntl.ioctl(
        s.fileno(),
        0x8915,  # SIOCGIFADDR
        struct.pack('256s', ifname[:15])
    )[20:24])

clientAddress = '192.168.2.1', 9999
serverAddress = localIP, 9998

lockerServer = OSCServer( serverAddress ) 
lockerServer.timeout = 0
run = True

lockerClient = OSCClient()
lockerClient.connect(clientAddress)

# Create a default object, no changes to I2C address or frequency
locker = Adafruit_MotorHAT(addr=0x60)

totalPixels = 1000		# Number of LEDs in Locker
pixel = 0

# Control Pins for the Raspberry Pi to the Dot Star strip
datapin   = 23
clockpin  = 24
#strip	  = Adafruit_DotStar(totalPixels, datapin, clockpin)
def main(stdcr):

    stdscr = curses.initscr()
    stdscr.nodelay(1)

    activeLight = False
    activeVideoOn = False
    activeVideoOff = False

    lastButtonCar = 1
    sentButtonCar = 0
    timerButtonCar = 0

    connected = False

    raspberryAddress = '192.168.0.197', 7100
    milluminAddress = '192.168.1.21', 5000
    milluminAddress2 = '192.168.1.22', 5000

    while not connected:

        try:
            server = OSCServer(raspberryAddress)
            server.timeout = 0

            # Creamos el objeto "Cliente"
            client = OSCClient()
            client2 = OSCClient()

            # Realizamos la conexion
            # client.connect( milluminAddress )
            # client2.connect( milluminAddress2 )

            connected = True

        except:
            print("No se encuentra el servidor OSC. Reintentando...")
            time.sleep(5)

    # funny python's way to add a method to an instance of a class
    server.handle_timeout = types.MethodType(handle_timeout, server)

    server.addMsgHandler("/1/lightPlus", callback_lightOn)
    server.addMsgHandler("/1/lightMinus", callback_lightOff)
    server.addMsgHandler("/1/videoOn1", callback_videoOn1)
    server.addMsgHandler("/1/videoOn1eng", callback_videoOn1eng)
    server.addMsgHandler("/1/videoOn2", callback_videoOn2)
    server.addMsgHandler("/1/videoOn2eng", callback_videoOn2eng)
    server.addMsgHandler("/1/videoOn3", callback_videoOn3)
    server.addMsgHandler("/1/videoOn4", callback_videoOn4)
    server.addMsgHandler("/1/videoStop", callback_videoStop)

    GPIO.setmode(GPIO.BCM)
    GPIO.setup(17, GPIO.OUT)  ## GPIO 17 como salida (bajar luz)
    GPIO.setup(27, GPIO.OUT)  ## GPIO 27 como salida (subir luz)
    GPIO.setup(
        22, GPIO.IN,
        pull_up_down=GPIO.PUD_UP)  ## GPIO 23 como entrada (boton iniciar show)

    time_stamp = time.time() - 30

    # simulate a "game engine"
    while True:

        while not connected:
            try:
                server = OSCServer(raspberryAddress)
                server.timeout = 0

                # Creamos el objeto "Cliente"
                client = OSCClient()
                client2 = OSCClient()

                # Realizamos la conexion
                client.connect(milluminAddress)
                client2.connect(milluminAddress2)

                connected = True

            except:
                # print("No se encuentra el servidor OSC. Reintentando...")
                stdscr.addstr(
                    "No se encuentra el servidor OSC. Reintentando..." + ' ')
                stdscr.refresh()
                # return curser to start position
                stdscr.move(0, 0)
                time.sleep(5)

        try:
            stdscr.move(0, 0)
            c = stdscr.getch()
            if c != -1:
                # print numeric value
                stdscr.addstr(str(c) + ' ')
                stdscr.refresh()
                # return curser to start position
                stdscr.move(0, 0)

            # do the game stuff:
            if activeLight:
                GPIO.output(17, False)

            else:
                GPIO.output(17, True)

            # print GPIO.input(22)

            if (GPIO.input(22) == 0) and (lastButtonCar == 1):

                timerButtonCar = time.time()
                lastButtonCar = 0
                # print "Inicio Pulso"

            elif (GPIO.input(22) == 0) and (lastButtonCar
                                            == 0) and (not sentButtonCar):

                delta = time.time() - timerButtonCar

                if delta > 1.0:
                    msg = OSCMessage()
                    msg.setAddress("/millumin/action/launchorStopColumn")
                    msg.append(9.0)
                    #client.send(msg) # now we dont need to tell the client the address anymore
                    #client2.send(msg) # now we dont need to tell the client the address anymore
                    sentButtonCar = True
                    # print "Lanzando mapping coche"
                    stdscr.addstr("Lanzando mapping coche..." + ' ')
                    stdscr.refresh()
                    # return curser to start position
                    stdscr.move(0, 0)

            elif (GPIO.input(22) == 1) and (lastButtonCar == 0):

                timerButtonCar = time.time()
                lastButtonCar = 1
                # print "Fin pulso"

            elif (GPIO.input(22) == 1) and (lastButtonCar
                                            == 1) and (sentButtonCar):

                if (time.time() - timerButtonCar > 1.0):

                    # print "Reseteando boton de coche"
                    sentButtonCar = False

            each_frame(server)

        except KeyboardInterrupt:

            #client.close()
            #client2.close()
            server.close()
            GPIO.cleanup()
Esempio n. 21
0
#!/usr/bin/env python3
# This code uses pylsl to open an LSLMarker connection and send markers. It
# receives the markers from Supercollider by using pyOSC to set up a OSCServer
# listening on port 7110. Supercollider then sends messages to this port.

from OSC import OSCServer
import sys
from time import sleep

from pylsl import StreamInfo, StreamOutlet

server = OSCServer(("localhost", 7110))
server.timeout = 0
run = True

# Make your pylsl connection
info = StreamInfo('LSL Marker Stream', 'Markers', 1, 0, 'string',
                  'myuidw43536')

# next make an outlet
outlet = StreamOutlet(info)


# this method of reporting timeouts only works by convention
# that before calling handle_request() field .timed_out is
# set to False
def handle_timeout(self):
    self.timed_out = True


# funny python's way to add a method to an instance of a class
Esempio n. 22
0
__author__ = 'benjamindeleener'
#!/usr/bin/env python3
from OSC import OSCServer
import sys
from time import sleep

server = OSCServer( ("localhost", 5005) )
server.timeout = 0
run = True

# this method of reporting timeouts only works by convention
# that before calling handle_request() field .timed_out is
# set to False
def handle_timeout(self):
    self.timed_out = True

# funny python's way to add a method to an instance of a class
import types
server.handle_timeout = types.MethodType(handle_timeout, server)

def user_callback(path, tags, args, source):
    # which user will be determined by path:
    # we just throw away all slashes and join together what's left
    user = ''.join(path.split("/"))
    # tags will contain 'ffff'
    # args is a OSCMessage with data
    # source is where the message came from (in case you need to reply)
    print ("Now do something with ", user, args[0], args[1], args[2], args[3])

def quit_callback(path, tags, args, source):
    # don't do this at home (or it'll quit blender)
Esempio n. 23
0
import time
from OSC import OSCServer
from subprocess import Popen, PIPE

import settings


def clean_screen():
    os.system('cls' if os.name == 'nt' else 'clear')


clean_screen()

srv_conn = (settings.OSC_LISTEN_ADDRESS, settings.OSC_LISTEN_PORT)
SERVER = OSCServer(srv_conn)
SERVER.timeout = settings.OSC_LISTENER_TIMEOUT
print "\n[>] Instantiated server: {}:{}".format(*srv_conn)

oscserver_run = True

# Add a method `handle_timeout` to an instance of OSCServer.
#
# tThis method of reporting timeouts only works by convention
# that before calling handle_request() the field .timed_out is
# set to False.
import types


def handle_timeout(self):
    self.timed_out = True