Example #1
0
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()
Example #2
0
 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---------------"
Example #3
0
 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**************"
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):
Example #5
0
#!/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
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):
Example #7
0
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
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):
        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)
Example #10
0
##############################################################
# 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
Example #11
0
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))
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)
Example #13
0
##############################################################
# YUXI SenseHat Example
# This script uses the SenseHat for Raspberry Pi to subscribe
# to letters which it displays on the LED Matrix. It is also
# wired to publish the joystick events on Spacebrew.
# Joystick: up, down, left, right
##############################################################

import sys
import time
from pySpacebrew.spacebrew import Spacebrew
from sense_hat import SenseHat

# Setup Spacebrew with Publishers and Subscribers
brew = Spacebrew("YUXI_SenseHat",
                 description="Joystick and LED letters",
                 server="ciidspacebrew.local",
                 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):
Example #14
0
#!/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):