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_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**************"
def spacebrew_connect(self): name = "booth-6-mac" # 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("concentration", "string") sb.addSubscriber("touching_forehead", "string") sb.addSubscriber("alpha_absolute", "string") sb.addSubscriber("beta_absolute", "string") sb.addSubscriber("gamma_absolute", "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("touching_forehead", self.sb_forehead_handler) sb.subscribe("mellon", self.sb_mellon_handler) sb.subscribe("concentration", self.sb_concentrate_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 spacebrew_connect(self): name = "booth-6-mac" # 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("concentration", "string") sb.addSubscriber("touching_forehead", "string") sb.addSubscriber("alpha_absolute", "string") sb.addSubscriber("beta_absolute", "string") sb.addSubscriber("gamma_absolute", "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("touching_forehead", self.sb_forehead_handler) sb.subscribe("mellow", self.sb_mellon_handler) sb.subscribe("concentration", self.sb_concentrate_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---------------"
w = [255, 255, 255] e = [0, 0, 0] current_rate = 1.0 sense.clear() def handleString(value): # grab only the first letter sent letter = value[0] print(letter) sense.show_letter(letter) time.sleep(0.5) sense.clear() brew.subscribe("letters", handleString) try: print("Press Ctrl-C to quit.") brew.start() while True: for event in sense.stick.get_events(): # Check if the joystick was pressed if event.action == "pressed": # Check which direction if event.direction == "up": sense.show_letter("U") # Up arrow elif event.direction == "down":
printer.println("Printer on") printer.feed(5) # get app name and server from query string name = "Xoup Printer" server = "server.sitetosite.co" # add subscriber brew = Spacebrew(name, server=server) brew.addSubscriber("incoming strings", "string") def handleString(value): printer.println(value) printer.feed(2) brew.subscribe("incoming strings", handleString) brew.start() filepath = "test.gif" buffer = open(filepath, 'rb').read() base64.b16encode(buffer) # printer.printBitmap(100, 100, buffer)
if (value / 10) > i: stdscr.addstr(" ".encode(code), curses.A_STANDOUT) else: stdscr.addstr(" ".encode(code)) stdscr.refresh() # function that handles the incoming spacebrew range messages def handleRange(value): global code, stdscr remote_state = int(value) displayRange(remote_state, col_remote) # registering range handler method with appropriate subscription feed brew.subscribe("graph", handleRange) try: brew.start() # set app information message info_msg = "This is the pySpacebrew library range example. This app sends out a range value, between 0 and 1023. The value \n" info_msg += "increases and decreases in response to '+'/'=' and `-`/'_' key presses. App also displays a range value received\n" info_msg += "from Spacebrew. Connected 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 of the local and remote range linds col_local = stdscr.getyx()[0] + 2 col_remote = col_local + 2
def motor1a(state): GPIO.output(17, str2bool(state)) def motor1b(state): GPIO.output(18, str2bool(state)) def motor2a(state): GPIO.output(22, str2bool(state)) def motor2b(state): GPIO.output(23, str2bool(state)) #add listeners brew.subscribe("motor1a", motor1a) brew.subscribe("motor1b", motor1b) brew.subscribe("motor2a", motor2a) brew.subscribe("motor2b", motor2b) try: brew.start() print "Spacebrew Started" while 1: pass finally: brew.stop() GPIO.cleanup()
brew.addSubscriber("motor1a","boolean") brew.addSubscriber("motor1b","boolean") brew.addSubscriber("motor2a","boolean") brew.addSubscriber("motor2b","boolean") #define functions def motor1a(state): GPIO.output(17,str2bool(state)) def motor1b(state): GPIO.output(18,str2bool(state)) def motor2a(state): GPIO.output(22,str2bool(state)) def motor2b(state): GPIO.output(23,str2bool(state)) #add listeners brew.subscribe("motor1a", motor1a) brew.subscribe("motor1b", motor1b) brew.subscribe("motor2a", motor2a) brew.subscribe("motor2b", motor2b) try: brew.start() print "Spacebrew Started" while 1: pass finally: brew.stop() GPIO.cleanup()
GPIO.setup(GREEN_LED, GPIO.OUT) GPIO.setup(RED_LED, GPIO.OUT) GPIO.setup(24, GPIO.IN) #down is False lightOn = False alreadySent = False # to 'debounce' the button def handleBoolean(value): global lightOn print("Received: " + str(value)) if (value == 'true' or str(value) == 'True'): lightOn = not lightOn # for handling messages coming through spacebrew brew.subscribe("flipLight", handleBoolean) try: brew.start() print("Press Ctrl-C to quit.") while True: GPIO.output(GREEN_LED, False) if (GPIO.input(24) == False): if (alreadySent == False): print("Button Pushed") brew.publish('buttonPress', True) alreadySent = True GPIO.output(GREEN_LED, lightOn) time.sleep(CHECK_FREQ) if (GPIO.input(24) == True): alreadySent = False
# configure the spacebrew client brew = Spacebrew(name, server=server) brew.addPublisher("chat outgoing", "string") brew.addSubscriber("chat incoming", "string") def handleString(value): global pos, code, stdscr stdscr.addstr(pos_in, 0, "incoming: ".encode(code), curses.A_BOLD) stdscr.addstr(pos_in, pos_msg, (" " * pos_max).encode(code)) stdscr.addstr(pos_in, pos["x"] + pos_msg, value.encode(code)) stdscr.refresh() pos["y"] += 1 brew.subscribe("chat incoming", handleString) # set-up a variables to hold current position pos = {"x": 0, "y": 0} # line positions pos_type = 0 pos_in = 0 pos_out = 0 # column positions pos_msg = 10 pos_max = 60 pos_con = pos_msg + pos_max + 5 try:
# 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
server = cur_ele[7:] # configure the spacebrew client brew = Spacebrew(name, server=local) brew.addPublisher("chat outgoing", "string") brew.addSubscriber("chat incoming", "string") def handleString(value): global pos, code, stdscr stdscr.addstr(pos_in, 0, "incoming: ".encode(code), curses.A_BOLD) stdscr.addstr(pos_in, pos_msg, (" " * pos_max).encode(code)) stdscr.addstr(pos_in, pos["x"] + pos_msg, value.encode(code)) stdscr.refresh() pos["y"] += 1 brew.subscribe("chat incoming", handleString) # set-up a variables to hold current position pos = { "x":0, "y":0 } # line positions pos_type = 0 pos_in = 0 pos_out = 0 # column positions pos_msg = 10 pos_max = 60 pos_con = pos_msg + pos_max + 5 try:
name = cur_ele[5:] if "server" in cur_ele: server = cur_ele[7:] # configure the spacebrew client brew = Spacebrew(name=name, server=server) brew.addPublisher("local state", "boolean") brew.addSubscriber("remote state", "boolean") def handleBoolean(value): global code, stdscr stdscr.addstr(pos_remote, pos_state, (str(value) + " ").encode(code)) stdscr.refresh() brew.subscribe("remote state", handleBoolean) 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 boolean example. It sends out a boolean message every time\n" info_msg += "the enter or return key is pressed and displays the latest boolean 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
brew = Spacebrew(name=name, server=server) brew.addPublisher("roll of the dice", "dice") brew.addSubscriber("what did you roll", "dice") # 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
stdscr.addstr(source_line, pos_state, "".encode(code)) for i in range(100): if (value / 10) > i: stdscr.addstr(" ".encode(code), curses.A_STANDOUT) else: stdscr.addstr(" ".encode(code)) stdscr.refresh() # function that handles the incoming spacebrew range messages def handleRange(value): global code, stdscr remote_state = int(value) displayRange(remote_state, col_remote) # registering range handler method with appropriate subscription feed brew.subscribe("graph", handleRange) try: brew.start() # set app information message info_msg = "This is the pySpacebrew library range example. This app sends out a range value, between 0 and 1023. The value \n" info_msg += "increases and decreases in response to '+'/'=' and `-`/'_' key presses. App also displays a range value received\n" info_msg += "from Spacebrew. Connected 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 of the local and remote range linds col_local = stdscr.getyx()[0] + 2 col_remote = col_local + 2