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 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**************"
local_state = False remote_state = False # get app name and server from query string name = "pyBoolean Example" server = "sandbox.spacebrew.cc" for cur_ele in sys.argv: if "name" in cur_ele: 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
curses.noecho() # turn off echo curses.curs_set(0) # turn off cursor # get app name and server from query string name = "pyString Example" server = "sandbox.spacebrew.cc" local = "localhost" for cur_ele in sys.argv: if "name" in cur_ele: name = cur_ele[5:] if "server" in cur_ele: 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 }
import sys import time from pySpacebrew.spacebrew import Spacebrew from sense_hat import SenseHat # Publish # Joystick shows a letter # publish up, down, left, right, middle # Subscribe to letters # Strings # publish button press - bool # listen for light changes - bool brew = Spacebrew("MRHT_SenseHat", description="Joystick and LED letters", server="10.10.2.47", port=9000) brew.addSubscriber("letters", "string") brew.addPublisher("joystick", "string") # Setup SenseHat for animation on LED array sense = SenseHat() sense.set_rotation(180) w = [255, 255, 255] e = [0, 0, 0] current_rate = 1.0 sense.clear() def handleString(value):
############################################################## # YUXI Lights and Buttons Example # This script uses a Button wired to pin 24 and an LED light # wired to pin 18. It publishes the button presses and listens # for Spacebrew events to turn the light on. To use the button # to turn off and on the light, connect them in Spacebrew. ############################################################## import sys import time from pySpacebrew.spacebrew import Spacebrew import RPi.GPIO as GPIO # Setup Spacebrew with Publishers and Subscribers brew = Spacebrew("YUXI_Light_Button", description="Python Light and Button controller", server="ciidspacebrew.local", port=9000) brew.addSubscriber("flipLight", "boolean") brew.addPublisher("buttonPress", "boolean") CHECK_FREQ = 0.1 # How often to check the hardware GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GREEN_LED = 18 RED_LED = 23 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
stdscr.keypad(1) curses.noecho() # turn off echo curses.curs_set(0) # turn off cursor # get app name and server from query string name = "pyString Example" server = "sandbox.spacebrew.cc" for cur_ele in sys.argv: if "name" in cur_ele: name = cur_ele[5:] if "server" in cur_ele: server = cur_ele[7:] # 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)
import sys import time from pySpacebrew.spacebrew import Spacebrew import RPi.GPIO as GPIO # listen for light changes - bool brew = Spacebrew("MRSwitch", description="Control light using mixed reality with PowerSwitch Tail 2", server="192.168.1.165", port=9000) brew.addSubscriber("flipLight", "boolean") # brew.addPublisher("buttonPress", "boolean") GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) powerSwitchPin = 24 GPIO.setup(powerSwitchPin, GPIO.OUT) GPIO.output(powerSwitchPin, GPIO.LOW) isLightOn = False i = 0 CHECK_FREQ = 0.1 #Sleep time for the loop def handleBoolean(value): print("Received: "+str(value)) global isLightOn if (value == 'true' or str(value) == 'True'): isLightOn = True if (value == 'false' or str(value)== 'False'): isLightOn = False # print(str(isLightOn))
pos_state = 18 local_state = 0 remote_state = 0 # get app name and server from query string name = "pyDice Example" server = "sandbox.spacebrew.cc" for cur_ele in sys.argv: if "name" in cur_ele: 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("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()
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5) # set printer formats printer.doubleHeightOn() printer.boldOn() printer.justify('L') 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"
stdscr.keypad(1) curses.noecho() # turn off echo curses.curs_set(0) # turn off cursor # get app name and server from query string name = "pyRange Example" server = "sandbox.spacebrew.cc" for cur_ele in sys.argv: if "name" in cur_ele: name = cur_ele[5:] if "server" in cur_ele: server = cur_ele[7:] # configure the spacebrew client brew = Spacebrew(name, server=server) brew.addPublisher("slider", "range") brew.addSubscriber("graph", "range") # set-up a variables to hold coordinates pos_state = 21 pos_int = 15 col_local = 0 col_remote = 0 # set-up a variables to hold state local_state = 500 remote_state = 0 # method that updates the range "bars" and value on the display def displayRange(value, source_line):
import serial import sys import time from pySpacebrew.spacebrew import Spacebrew ser = serial.Serial('/dev/tty.usbserial-AD01SUMG', 9600) connected = False # GENERAL IDEA # Listen for events coming from the arduino and forward them as Spacebrew Events # bool, string, range # Take Spacebrew events and forward them to the arduino # bool, string, range # setup Spacebrew brew = Spacebrew("pyRFID", description="Python contolled rfid scanner", server="beaglebone.local", port=9000) brew.addPublisher("rfidscan", "string") brew.start() while True: message = ser.readline() connected = True print(message) brew.publish('rfidscan', message) time.sleep(0.1) ser.close
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---------------"
GPIO.setup(23, GPIO.OUT) time.sleep(1) print "Opening Configuration" config = open('robotConfig.txt', 'r') jsonData = json.load(config) print "Robot loaded as: " + str(jsonData["robotName"]) #print "Checking if wi-fi configuration needs changing" #if(jsonData['wifi-update']==1): # print"Updating Wi-Fi" print "Attempting to connect to spacebrew server: " + str( jsonData["robotServer"]) brew = Spacebrew(name=str(jsonData["robotName"]), server=str(jsonData["robotServer"])) #configure motors 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):
#!/usr/bin/env python #import libraries import sys import time import subprocess #import Spacebrew from pySpacebrew.spacebrew import Spacebrew #create Spacebrew object brew = Spacebrew( "MRHT_Micol_Joyfishing", description= "The IMU Unit wasn't giving back sensed data so we decided to use the joystick", server="192.168.1.165", port=9000) #to use Pi as an OUTPUT #brew.addSubscriber("name", "type") #to use Pi as an INPUT brew.addPublisher("up", "boolean") brew.addPublisher("down", "boolean") brew.addPublisher("left", "boolean") brew.addPublisher("left", "boolean") brew.addPublisher("buttonPress", "boolean") #define state of the Pi, initially it is not connected connected = False
s.connect(('10.255.255.255', 1)) IP = s.getsockname()[0] except: IP = '127.0.0.1' finally: s.close() return IP # Create MPR121 instance. cap = MPR121.MPR121() # Setup Spacebrew for Publishing brew = Spacebrew("YUXI_PlayTheRoom : " + macString[-5:], description='[ capacitiveSwitches ] [local ip' + get_ip() + '] [MAC Address ' + macString + '] ', server="sandbox.spacebrew.cc", port=9000) for i in range(12): brew.addPublisher('P{0}'.format(i), 'boolean') connected = False # Initialize communication with MPR121 using default I2C bus of device, and # default I2C address (0x5A). On BeagleBone Black will default to I2C bus 0. if not cap.begin(): print('Error initializing MPR121. Check your wiring!') sys.exit(1) # Alternatively, specify a custom I2C address such as 0x5B (ADDR tied to 3.3V), # 0x5C (ADDR tied to SDA), or 0x5D (ADDR tied to SCL). #cap.begin(address=0x5B)
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---------------"
GPIO.setup(22, GPIO.OUT) GPIO.setup(23, GPIO.OUT) time.sleep(1) print "Opening Configuration" config = open('robotConfig.txt','r') jsonData = json.load(config) print "Robot loaded as: " + str(jsonData["robotName"]) #print "Checking if wi-fi configuration needs changing" #if(jsonData['wifi-update']==1): # print"Updating Wi-Fi" print "Attempting to connect to spacebrew server: " + str(jsonData["robotServer"]) brew = Spacebrew(name=str(jsonData["robotName"]), server=str(jsonData["robotServer"])) #configure motors 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))
import sys import time from pySpacebrew.spacebrew import Spacebrew import RPi.GPIO as GPIO import Adafruit_MPR121.MPR121 as MPR121 # Create MPR121 instance. cap = MPR121.MPR121() if not cap.begin(): print('Error initializing MPR121. Check your wiring!') sys.exit(1) # publish button press - bool # listen for light changes - bool brew = Spacebrew("MRHT_Light_Button", description="Python Light and Button controller", server="192.168.1.165", port=9000) #brew.addSubscriber("flipLight", "boolean") brew.addPublisher("buttonPress", "boolean") CHECK_FREQ = 0.1 # check mail every 60 seconds GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) #GREEN_LED = 18 #RED_LED = 23 #GPIO.setup(GREEN_LED, GPIO.OUT) #GPIO.setup(RED_LED, GPIO.OUT) #GPIO.setup(24, GPIO.IN) #lightOn = False #def handleBoolean(value):
stdscr.keypad(1) curses.noecho() # turn off echo curses.curs_set(0) # turn off cursor # get app name and server from query string name = "pyRange Example" server = "sandbox.spacebrew.cc" for cur_ele in sys.argv: if "name" in cur_ele: name = cur_ele[5:] if "server" in cur_ele: server = cur_ele[7:] # configure the spacebrew client brew = Spacebrew(name, server=server) brew.addPublisher("slider", "range") brew.addSubscriber("graph", "range") # set-up a variables to hold coordinates pos_state = 21 pos_int = 15 col_local = 0 col_remote = 0 # set-up a variables to hold state local_state = 500 remote_state = 0 # method that updates the range "bars" and value on the display
pos_state = 18 local_state = 0 remote_state = 0 # get app name and server from query string name = "pyDice Example" server = "sandbox.spacebrew.cc" for cur_ele in sys.argv: if "name" in cur_ele: 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("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)
#!/usr/bin/env python ############################################################## # YUXI Hello World Example # This script will ask the Raspberry Pi for what wifi networks # it can see and then send them as Spacebrew events ############################################################## import sys import time import subprocess from pySpacebrew.spacebrew import Spacebrew # Setup Spacebrew for Publishing brew = Spacebrew("YUXI_HelloWorld", description="Animate some wifi networks", server="ciidspacebrew.local", port=9000) brew.addPublisher("networkEvent", "boolean") brew.addPublisher("wifi", "string") connected = False CHECK_FREQ = 2 # time to sleep between adding items CURR_INDEX = 0 # Create a queue of items def makeArray(): # Check for a list of wifi networks that the RPi can see cmdCall = subprocess.check_output('sudo iwlist wlan0 scan | grep ESSID', shell=True) output = cmdCall.decode("utf-8").splitlines() for i, s in enumerate(output):