def spacebrew_connect(self): name = "booth-6" # server = "server.neuron.brain" local_server = "localhost" sb = Spacebrew(name, server=SERVER_IP) sb.addPublisher("test pub", "string") sb.addSubscriber("eeg", "string") sb.addSubscriber("connect", "string") sb.addSubscriber("disconnect", "string") sb.addSubscriber("mellow", "string") sb.addSubscriber("alpha_relative", "string") sb.addSubscriber("beta_relative", "string") sb.addSubscriber("gamma_relative", "string") # sb.subscribe("eeg", self.eeg_handler_test) sb.subscribe("eeg", self.sb_eeg_handler) sb.subscribe("connect", self.sb_connect_handler) sb.subscribe("disconnect", self.sb_disconnected_handler) sb.subscribe("mellow", self.sb_mellon_handler) sb.subscribe("alpha_relative", self.sb_alpha_handler) sb.subscribe("beta_relative", self.sb_alpha_handler) sb.subscribe("gamma_relative", self.sb_gamma_handler) # data from local muse data = "test" sb.start() print "---------------streaming starts---------------"
def cloud_ros(): name = "rosPy Example" server = "localhost" #server = "sandbox.spacebrew.cc" global brew brew = Spacebrew(name=name, server=server) brew.addPublisher("Publisher") brew.addSubscriber("Subscriber") try: # start-up spacebrew brew.start() brew.subscribe("Subscriber", received) thread2 = myThread(1, "Thread-2", 1) thread2.start() finally: rospy.init_node('cloud_ros_node') rospy.loginfo("cloud_ros node is up and running!!!") s = rospy.Service('send_data', Comando, send) rospy.spin()
def spacebrew_connect(self): name = "booth-6" # server = "server.neuron.brain" local_server = "localhost" sb = Spacebrew(name, server=SERVER_IP) sb.addPublisher("test pub", "string") sb.addSubscriber("eeg", "string") sb.addSubscriber("connect", "string") sb.addSubscriber("disconnect", "string") sb.addSubscriber("mellon", "string") sb.addSubscriber("alpha_relative", "string") sb.addSubscriber("beta_relative", "string") sb.addSubscriber("gamma_relative", "string") # sb.subscribe("eeg", self.eeg_handler_test) sb.subscribe("eeg", self.sb_eeg_handler) sb.subscribe("connect", self.sb_connect_handler) sb.subscribe("disconnect", self.sb_disconnected_handler) sb.subscribe("mellon", self.sb_mellon_handler) sb.subscribe("alpha_relative", self.sb_alpha_handler) sb.subscribe("beta_relative", self.sb_alpha_handler) sb.subscribe("gamma_relative", self.sb_gamma_handler) # data from local muse data = "test" sb.start() print "---------------streaming starts---------------"
def main(): parser = argparse.ArgumentParser(description="Hue to Spacebrew bridge") parser.add_argument("-s", "--server", help="Spacebrew server", default="sandbox.spacebrew.cc") parser.add_argument("-p", "--port", help="Spacebrew port", type=int, default=9000) parser.add_argument("-b", "--bridge", help="Hue bridge") args = parser.parse_args() print("Connecting to Spacebrew server: %s port %d"%(args.server, args.port)) brew = Spacebrew("Hue Bridge", server=args.server, port=args.port) if args.bridge is None: info = urllib.urlopen('http://www.meethue.com/api/nupnp').read() info = json.loads(info) if len(info) > 0: args.bridge = info[0][u'internalipaddress'] else: print("ERROR: Could not auto-detect Hue bridge IP") print(" Please specify --bridge manually") sys.exit(1) print("Connecting to Hue bridge at: %s" % args.bridge) bridge = None while bridge == None: try: bridge = Bridge(args.bridge) except phue.PhueRegistrationException as e: print(str(e)) sleep(5) lights = bridge.get_light_objects('name') brew_lights = [] print("Lights:") for name in lights: print(" - %s"%(name)) brew_lights.append(HueBulb(brew, name, lights[name])) print("Starting Spacebrew") brew.start() sleep(5) try: while True: for light in brew_lights: light.poll() # chill out man sleep(0.33) finally: brew.stop()
def spacebrew_pub_test(self): data = "hi unity!!!!!!!!!!!!!!" name = "booth-6-pub" server = "localhost" sb = Spacebrew(name, server=server) sb.addPublisher("test-pub", "string") sb.addSubscriber("test-sub", "string") sb.subscribe("test-sub", self.sb_handler) sb.start() print "**************streaming starts**************"
# function that handles the incoming spacebrew dice messages def handleDice(value): global code, stdscr stdscr.addstr(pos_remote, pos_state, (" " * 30).encode(code)) if value < 1 or value > 6: stdscr.addstr(pos_remote, pos_state, ("you rolled a " + str(value) + "! What kind of dice is that? ").encode(code)) else: stdscr.addstr(pos_remote, pos_state, str(value).encode(code)) stdscr.refresh() # register handler function with appropriate subscription data feed brew.subscribe("what did you roll", handleDice) try: # start-up spacebrew brew.start() # create and load info message at the top of the terminal window info_msg = "This is the pySpacebrew library custom data type example. It rolls the dice every time the enter or return\n" info_msg += "key is pressed (value between 0 and 6), and displays the latest dice roll value it has received.\n" info_msg += "Connected to Spacebrew as: " + name + "\n" info_msg += "IMPORTANT: don't shrink the Terminal window as it may cause app to crash (bug with curses lib)." stdscr.addstr(0, 0, info_msg.encode(code)) stdscr.refresh() # update the location for the remote and local dice state pos_local = stdscr.getyx()[0] + 2 pos_remote = pos_local + 2 # display the label for the remote and local dice roll states stdscr.addstr(pos_local, 0, "local dice roll: ".encode(code), curses.A_BOLD)
# # Each pin is represented by a bit in the touched value. A value of 1 # # means the pin is being touched, and 0 means it is not being touched. # pin_bit = 1 << i # # First check if transitioned from not touched to touched. # if current_touched & pin_bit and not last_touched & pin_bit: # print('{0} touched!'.format(i)) # # Next check if transitioned from touched to not touched. # if not current_touched & pin_bit and last_touched & pin_bit: # print('{0} released!'.format(i)) # # Update last state and wait a short period before repeating. # last_touched = current_touched # time.sleep(0.1) try: brew.start() #print("Should be looping") print("Press Ctrl-C to quit.") while True: #print("LOOP") # GPIO.output(GREEN_LED, False) if cap.is_touched(0): print("Button 0 Pushed") brew.publish('buttonPress', True) # GPIO.output(GREEN_LED, lightOn) time.sleep(CHECK_FREQ) finally: GPIO.cleanup() brew.stop()