Example #1
0
def config_socket(ledCount):
    # Define zmq socket
    context = zmq.Context()
    # Create a Pusher socket
    socket = context.socket(zmq.PUSH)
    # Connect Pusher to configuration socket
    socket.connect('tcp://{0}:{1}'.format(matrix_ip, everloop_port))

    # Loop forever
    while True:
        # Create a new driver config
        driver_config_proto = driver_pb2.DriverConfig()
        # Create an empty Everloop image
        image = []
        # For each device LED
        for led in range(ledCount):
            # Set individual LED value
            ledValue = io_pb2.LedValue()
            ledValue.blue = randint(0, 50)
            ledValue.red = randint(0, 200)
            ledValue.green = randint(0, 255)
            ledValue.white = 0
            image.append(ledValue)
        # Store the Everloop image in driver configuration
        driver_config_proto.image.led.extend(image)

        # Send driver configuration through ZMQ socket
        socket.send(driver_config_proto.SerializeToString())
        #Wait before restarting loop
        time.sleep(0.05)
Example #2
0
def set_everloop_intensity(intensity):
    """Sets all of the LEDS to a given rgbw value"""

    # grab zmq context
    context = zmq.Context()

    # get socket for config
    config_socket = context.socket(zmq.PUSH)
    config_socket.connect('tcp://{0}:{1}'.format(creator_ip, creator_everloop_base_port))

    # create a new driver config strut
    config = driver_pb2.DriverConfig()

    # initialize an empty list for the "image" or LEDS
    image = []

    # iterate over all 35 LEDS and set the rgbw value of each
    # then append it to the end of the list/image thing
    for led in range(35):
        ledValue = io_pb2.LedValue()
        ledValue.blue = 0
        ledValue.red = 0
        ledValue.green = intensity
        ledValue.white = 0
        image.append(ledValue)

    # add the "image" to the config driver
    config.image.led.extend(image)

    # send a serialized string of the driver config
    # to the config socket
    config_socket.send(config.SerializeToString())
Example #3
0
def ring_image(led_count, ledOn):
    # Create a new driver config
    driver_config_proto = driver_pb2.DriverConfig()
    # Create an empty Everloop image
    image = []
    # Set individual LED value
    for led in range(led_count):
        if led in ledOn:
            ledValue = io_pb2.LedValue(
            )  # Protocol buffer custom type for Matrix Voice
            ledValue.blue = ledOn[led]["blue"]
            ledValue.red = ledOn[led]["red"]
            ledValue.green = ledOn[led]["green"]
            ledValue.white = ledOn[led]["white"]
            image.append(ledValue)
        else:
            ledValue = io_pb2.LedValue()
            ledValue.blue = 0
            ledValue.red = 0
            ledValue.green = 0
            ledValue.white = 0
            image.append(ledValue)
    # Store the Everloop image in driver configuration
    driver_config_proto.image.led.extend(image)
    return driver_config_proto.SerializeToString()
Example #4
0
def send_servo_command(pin):
    # Define zmq socket
    context = zmq.Context()
    # Create a Pusher socket
    socket = context.socket(zmq.PUSH)
    # Connect Pusher to configuration socket
    socket.connect('tcp://{0}:{1}'.format(matrix_ip, servo_port))

    # Create a new driver config
    servo_config = driver_pb2.DriverConfig()
    # Set a pin that the servo will operate on
    servo_config.servo.pin = pin

    # Function to change servo angle
    def moveServo(angle):
        # Log angle
        print('Angle: {0}'.format(angle))
        # Set the servo's angle in the config
        servo_config.servo.angle = angle
        # Serialize the config and send it to the driver
        socket.send(servo_config.SerializeToString())
        # Wait for 1 second
        time.sleep(1)
        # Run function again with random angle
        moveServo(random.randint(0, 180))

    # Initial moveServo call
    moveServo(180)
Example #5
0
    def construct_config_proto(self):
        # Create a new driver config
        driver_config_proto = driver_pb2.DriverConfig()

        driver_config_proto.delay_between_updates = 1.0
        driver_config_proto.timeout_after_last_ping = 1.0

        return driver_config_proto
Example #6
0
def _create_everloop_color_config(led_array):
    """Set everloop colors"""
    config = driver_pb2.DriverConfig()

    # add the led colors array to the config driver
    config.image.led.extend(led_array)

    return config
Example #7
0
 def IsGatewayActive(self):
     _LOGGER.info('Checking connection with the Gateway')
     driver_config_proto = driver_pb2.DriverConfig()
     driver_config_proto.zigbee_message.type = comm_pb2.ZigBeeMsg.ZigBeeCmdType.Value(
         "NETWORK_MGMT")
     driver_config_proto.zigbee_message.network_mgmt_cmd.type = comm_pb2.ZigBeeMsg.NetworkMgmtCmd.NetworkMgmtCmdTypes.Value(
         "IS_PROXY_ACTIVE")
     self.push(driver_config_proto)
     return Status.CHECK_GATEWAY_ACTIVE
Example #8
0
def config_gpio_read():
    # Create a new driver config
    config = driver_pb2.DriverConfig()
    # Delay between updates in seconds
    config.delay_between_updates = 2.0
    # Timeout after last ping
    config.timeout_after_last_ping = 3.5
    # Send driver configuration through ZMQ socket
    socket.send(config.SerializeToString())
Example #9
0
 def RequestNetworkStatus(self):
     _LOGGER.info('Requesting network status')
     driver_config_proto = driver_pb2.DriverConfig()
     driver_config_proto.zigbee_message.type = comm_pb2.ZigBeeMsg.ZigBeeCmdType.Value(
         "NETWORK_MGMT")
     driver_config_proto.zigbee_message.network_mgmt_cmd.type = comm_pb2.ZigBeeMsg.NetworkMgmtCmd.NetworkMgmtCmdTypes.Value(
         "NETWORK_STATUS")
     driver_config_proto.zigbee_message.network_mgmt_cmd.permit_join_params.time = 60
     self.push(driver_config_proto)
     return Status.WAITING_FOR_NETWORK_STATUS
Example #10
0
 def ResetGateway(self):
     _LOGGER.info('Reseting the Gateway App')
     _LOGGER.info(_comm_pb2.ZigBeeMsg.ZigBeeCmdType.keys())
     driver_config_proto = driver_pb2.DriverConfig()
     driver_config_proto.zigbee_message.type = comm_pb2.ZigBeeMsg.ZigBeeCmdType.Value(
         "NETWORK_MGMT")
     driver_config_proto.zigbee_message.network_mgmt_cmd.type = comm_pb2.ZigBeeMsg.NetworkMgmtCmd.NetworkMgmtCmdTypes.Value(
         "RESET_PROXY")
     self.push(driver_config_proto)
     return Status.RESET_GATEWAY
Example #11
0
    def CreateNetwork(self):
        _LOGGER.info('NO NETWORK')
        _LOGGER.info('CREATING A ZigBee Network')

        driver_config_proto = driver_pb2.DriverConfig()
        driver_config_proto.zigbee_message.type = comm_pb2.ZigBeeMsg.ZigBeeCmdType.Value(
            "NETWORK_MGMT")
        driver_config_proto.zigbee_message.network_mgmt_cmd.type = comm_pb2.ZigBeeMsg.NetworkMgmtCmd.NetworkMgmtCmdTypes.Value(
            "CREATE_NWK")
        driver_config_proto.zigbee_message.network_mgmt_cmd.permit_join_params.time = 60
        self.push(driver_config_proto)
        return Status.WAITING_FOR_NETWORK_STATUS
Example #12
0
    def PermitJoin(self):
        _LOGGER.info('Permitting join')
        driver_config_proto = driver_pb2.DriverConfig()
        driver_config_proto.zigbee_message.type = comm_pb2.ZigBeeMsg.ZigBeeCmdType.Value(
            "NETWORK_MGMT")
        driver_config_proto.zigbee_message.network_mgmt_cmd.type = comm_pb2.ZigBeeMsg.NetworkMgmtCmd.NetworkMgmtCmdTypes.Value(
            "PERMIT_JOIN")
        driver_config_proto.zigbee_message.network_mgmt_cmd.permit_join_params.time = 60
        self.push(driver_config_proto)

        _LOGGER.info('Please reset your zigbee devices')
        _LOGGER.info('.. Waiting 60s for new devices')
        return Status.WAITING_FOR_DEVICES
Example #13
0
def setEverloopColor(red=0, green=0, blue=0, white=0):
    config = driver_pb2.DriverConfig()
    image = []
    for led in range(35):
        ledValue = io_pb2.LedValue()
        ledValue.blue = blue
        ledValue.red = red
        ledValue.green = green
        ledValue.white = white
        image.append(ledValue)

    config.image.led.extend(image)
    config_socket.send(config.SerializeToString())
Example #14
0
    def toggle(self):
        config = driver_pb2.DriverConfig()

        config.zigbee_message.type = comm_pb2.ZigBeeMsg.ZigBeeCmdType.Value(
            "ZCL")
        config.zigbee_message.zcl_cmd.type = comm_pb2.ZigBeeMsg.ZCLCmd.ZCLCmdType.Value(
            "ON_OFF")
        config.zigbee_message.zcl_cmd.onoff_cmd.type = comm_pb2.ZigBeeMsg.ZCLCmd.OnOffCmd.ZCLOnOffCmdType.Value(
            "TOGGLE")
        config.zigbee_message.zcl_cmd.node_id = self._nodeId
        config.zigbee_message.zcl_cmd.endpoint_index = self._endpointIndex

        self.push(config)
Example #15
0
def speaking_leds():
    driver_config_proto = driver_pb2.DriverConfig()
    everloop_image = []
    for i in range(0, 35):
        led_value = io_pb2.LedValue()
        # set red brightness to 100
        led_value.white = 20
        # append that led configuration to led container
        everloop_image.append(led_value)
    # put the image into driver
    driver_config_proto.image.led.extend(everloop_image)
    # send the configuration to the driver
    socket.send(driver_config_proto.SerializeToString())
    return None
Example #16
0
    def set_color_temp(self, color_temp):
        self._colorTemp = color_temp
        config = driver_pb2.DriverConfig()

        config.zigbee_message.type = comm_pb2.ZigBeeMsg.ZigBeeCmdType.Value(
            "ZCL")
        config.zigbee_message.zcl_cmd.type = comm_pb2.ZigBeeMsg.ZCLCmd.ZCLCmdType.Value(
            "COLOR_CONTROL")
        config.zigbee_message.zcl_cmd.colorcontrol_cmd.type = comm_pb2.ZigBeeMsg.ZCLCmd.ColorControlCmd.ZCLColorControlCmdType.Value(
            "MOVETOCOLORTEMP")
        config.zigbee_message.zcl_cmd.colorcontrol_cmd.movetocolortemp_params.color_temperature = color_temp
        config.zigbee_message.zcl_cmd.colorcontrol_cmd.movetocolortemp_params.transition_time = 10
        config.zigbee_message.zcl_cmd.node_id = self._nodeId
        config.zigbee_message.zcl_cmd.endpoint_index = self._endpointIndex

        self.push(config)
Example #17
0
    def set_brightness(self, brightness):
        self._brightness = brightness
        config = driver_pb2.DriverConfig()

        config.zigbee_message.type = comm_pb2.ZigBeeMsg.ZigBeeCmdType.Value(
            "ZCL")
        config.zigbee_message.zcl_cmd.type = comm_pb2.ZigBeeMsg.ZCLCmd.ZCLCmdType.Value(
            "LEVEL")
        config.zigbee_message.zcl_cmd.level_cmd.type = comm_pb2.ZigBeeMsg.ZCLCmd.LevelCmd.ZCLLevelCmdType.Value(
            "MOVE_TO_LEVEL")
        config.zigbee_message.zcl_cmd.level_cmd.move_to_level_params.level = brightness
        config.zigbee_message.zcl_cmd.level_cmd.move_to_level_params.transition_time = 10
        config.zigbee_message.zcl_cmd.node_id = self._nodeId
        config.zigbee_message.zcl_cmd.endpoint_index = self._endpointIndex

        self.push(config)
def config_gpio_write(pin, value):
    """This function sets up a pin for use as an output pin"""

    # Create a new driver config
    config = driver_pb2.DriverConfig()

    # set the pin in the config provided from the function params
    config.gpio.pin = pin

    # Set pin mode to output
    config.gpio.mode = io_pb2.GpioParams.OUTPUT

    # Set the output of the pin initially
    config.gpio.value = value

    # Send configuration to malOS using global sconfig
    sconfig.send(config.SerializeToString())
Example #19
0
def config_socket():
    # Define zmq socket
    context = zmq.Context()
    # Create a Pusher socket
    socket = context.socket(zmq.PUSH)
    # Connect Pusher to configuration socket
    socket.connect('tcp://{0}:{1}'.format(matrix_ip, imu_port))

    # Create a new driver config
    driver_config_proto = driver_pb2.DriverConfig()
    # Delay between updates in seconds
    driver_config_proto.delay_between_updates = 0.05
    # Timeout after last ping
    driver_config_proto.timeout_after_last_ping = 6.0

    # Send driver configuration through ZMQ socket
    socket.send(driver_config_proto.SerializeToString())
Example #20
0
def config_gpio_write(pin, value):
    # Create a new driver config
    config = driver_pb2.DriverConfig()
    # set desired pin
    config.gpio.pin = pin
    # Set pin mode to output
    config.gpio.mode = io_pb2.GpioParams.OUTPUT
    # Set the output of the pin initially
    config.gpio.value = value%2
    # Send driver configuration through ZMQ socket
    socket.send(config.SerializeToString())

    # Wait 2 seconds
    time.sleep(2)
    # Increase value and run again
    value += 1
    config_gpio_write(0, value%2)
Example #21
0
    def __init__(self, numLeds, matrixIp, everloopPort):
        self._logger = logging.getLogger('SnipsLedControl')
        self._numLeds = numLeds
        self._matrixIp = matrixIp
        self._everloopPort = everloopPort

        self._driver = driver_pb2.DriverConfig()
        self._context = zmq.Context()
        self._socket = self._context.socket(zmq.PUSH)

        self._colors = self._newArray()

        ioloop.install()
        Process(target=register_error_callback,
                args=(self.everloopErrorCallback, self._matrixIp,
                      self._everloopPort)).start()
        self.pingSocket()
        self.updateSocket()
        self.configSocket(self._numLeds)
Example #22
0
def send_servo_command(pin=4):
    # or local ip of MATRIX creator
    creator_ip = '127.0.0.1'
    creator_servo_base_port = 20013 + 32

    # Set a base count of 0
    count = 0

    # Grab a zmq context and set it up as a push socket, then connect
    context = zmq.Context()
    socket = context.socket(zmq.PUSH)
    socket.connect('tcp://{0}:{1}'.format(creator_ip, creator_servo_base_port))

    # Create a new driver configuration
    servo_config = driver_pb2.DriverConfig()

    # Set a pin that the servo will operate on
    servo_config.servo.pin = pin

    # Start the loop of forever
    while True:
        # count mod 180 will set the angle of the servo to move to
        # this will change as the count increments to values of half turns
        angle = count % 180

        # Print out the angle to stdout
        print('Angle: {0}'.format(angle))

        # Set the servo's angle in the config
        servo_config.servo.angle = angle

        # since python isn't IO bound like node this will simulate
        # the event loop, updating the angle all the time but
        # only updating the servo every 1500000 'ticks'
        if count % 1500000 == 0:
            # Print message to stdout
            print('Sending new config to servo...{0}'.format(count))

            # Serialize the config and send it to the driver
            socket.send(servo_config.SerializeToString())

        # Increment the counter
        count += 1
Example #23
0
def config_socket():
    # Define zmq socket
    context = zmq.Context()
    # Create a Pusher socket
    socket = context.socket(zmq.PUSH)
    # Connect Pusher to configuration socket
    socket.connect('tcp://{0}:{1}'.format(matrix_ip, humidity_port))

    # Create a new driver config
    driver_config_proto = driver_pb2.DriverConfig()
    # Delay between updates in seconds
    driver_config_proto.delay_between_updates = 2.0
    # Timeout after last ping
    driver_config_proto.timeout_after_last_ping = 6.0
    # Current temperature in Celsius for calibration
    driver_config_proto.humidity.current_temperature = 23

    # Send driver configuration through ZMQ socket
    socket.send(driver_config_proto.SerializeToString())
def config_gpio_read(pin):
    """This function sets up a pin for use as an input pin"""

    # Create a new driver config
    config = driver_pb2.DriverConfig()

    # Set 250 miliseconds between updates.
    config.delay_between_updates = 0.5

    # Stop sending updates 2 seconds after pings.
    config.timeout_after_last_ping = 3.5

    # Set the pin to the value provided by the function param
    config.gpio.pin = pin

    # Set the pin mode to input
    config.gpio.mode = io_pb2.GpioParams.INPUT

    # Send configuration to malOS using global sconfig
    sconfig.send(config.SerializeToString())
def set_everloop_color(red=0, green=0, blue=0, white=0):
    """Submit a R,G,B,W value between 0-255"""

    # or local ip of MATRIX creator
    creator_ip = '127.0.0.1'

    # port for everloop driver
    creator_everloop_base_port = 20013 + 8

    # grab zmq context
    context = zmq.Context()

    # get socket for config
    config_socket = context.socket(zmq.PUSH)
    config_socket.connect('tcp://{0}:{1}'.format(creator_ip,
                                                 creator_everloop_base_port))

    # create a new driver config strut
    config = driver_pb2.DriverConfig()

    # initialize an empty list for the "image" or LEDS
    image = []

    # iterate over all 35 LEDS and set the rgbw value of each
    # then append it to the end of the list/image thing
    for led in range(35):
        ledValue = io_pb2.LedValue()
        ledValue.blue = blue
        ledValue.red = red
        ledValue.green = green
        ledValue.white = white
        image.append(ledValue)

    # add the "image" to the config driver
    config.image.led.extend(image)

    # send a serialized string of the driver config
    # to the config socket
    config_socket.send(config.SerializeToString())
Example #26
0
def config_socket():
    # Define zmq socket
    context = zmq.Context()
    # Create a Pusher socket
    socket = context.socket(zmq.PUSH)
    # Connect Pusher to configuration socket
    socket.connect('tcp://{0}:{1}'.format(matrix_ip, wakeword_port))

    # Create a new driver config
    config = driver_pb2.DriverConfig()
    # Language Model File
    config.wakeword.lm_path = LM_PATH
    # Dictation File
    config.wakeword.dic_path = DIC_PATH
    # Desired MATRIX microphone
    config.wakeword.channel = 8
    # Enable verbose option
    config.wakeword.enable_verbose = False

    # Send driver configuration through ZMQ socket
    socket.send(config.SerializeToString())
    print('Listening for wakewords')
Example #27
0
def config_socket():
    """Configure and calibrate the humidity driver"""

    # Grab the zmq context and set it to push, then connect to it
    context = zmq.Context()
    socket = context.socket(zmq.PUSH)
    socket.connect('tcp://{0}:{1}'.format(creator_ip, humidity_port))

    # Create a new driver config
    driver_config_proto = driver_pb2.DriverConfig()

    # Set the delay between updates that the driver returns
    driver_config_proto.delay_between_updates = 2.0

    # Stop sending updates if there is no ping for 6 seconds
    driver_config_proto.timeout_after_last_ping = 6.0

    # Calibrate the temperature by taking a real world
    # measurment from a thermometer and enter it in here
    # in degrees celcius
    driver_config_proto.humidity.current_temperature = 23

    # Serialize the config and send it to the config socket
    socket.send(driver_config_proto.SerializeToString())
Example #28
0
def config_socket(ledCount):
    global flag
    global Color
    # Define zmq socket
    context = zmq.Context()
    # Create a Pusher socket
    socket = context.socket(zmq.PUSH)
    # Connect Pusher to configuration socket
    socket.connect('tcp://{0}:{1}'.format(matrix_ip, everloop_port))

    rc = 0

    driver_config_proto = driver_pb2.DriverConfig()
    # Create an empty Everloop image
    image = []
    # For each device LED
    for led in range(ledCount):
        # Set individual LED value
        ledValue = io_pb2.LedValue()
        ledValue.blue = 10
        ledValue.red = 10
        ledValue.green = 10
        ledValue.white = 0
        image.append(ledValue)

    # Store the Everloop image in driver configuration
    driver_config_proto.image.led.extend(image)

    # Send driver configuration through ZMQ socket
    socket.send(driver_config_proto.SerializeToString())

    client = mqtt.Client()
    client.connect("raspberrypi.local", 1883)
    client.subscribe("hermes/nlu/intentParsed")
    client.subscribe("esp/test")
    client.on_message = on_message
    client.on_connect = on_connect
    client.on_publish = on_publish
    client.on_subscribe = on_subscribe
    client.on_log = on_log

    while rc == 0:
        rc = client.loop()
        if (flag):
            # Create a new driver config
            driver_config_proto = driver_pb2.DriverConfig()
            # Create an empty Everloop image
            image = []
            # For each device LED
            if (Color == "red"):
                for led in range(ledCount):
                    # Set individual LED value
                    ledValue = io_pb2.LedValue()
                    ledValue.blue = 0
                    ledValue.red = 100
                    ledValue.green = 0
                    ledValue.white = 0
                    image.append(ledValue)
            elif (Color == "blue"):
                for led in range(ledCount):
                    # Set individual LED value
                    ledValue = io_pb2.LedValue()
                    ledValue.blue = 100
                    ledValue.red = 0
                    ledValue.green = 0
                    ledValue.white = 0
                    image.append(ledValue)
            elif (Color == "green"):
                client.publish("esp/lock", "Hello")
                for led in range(ledCount):
                    # Set individual LED value
                    ledValue = io_pb2.LedValue()
                    ledValue.blue = 0
                    ledValue.red = 0
                    ledValue.green = 100
                    ledValue.white = 0
                    image.append(ledValue)
            else:
                for led in range(ledCount):
                    # Set individual LED value
                    ledValue = io_pb2.LedValue()
                    ledValue.blue = 10
                    ledValue.red = 10
                    ledValue.green = 10
                    ledValue.white = 0
                    image.append(ledValue)

            # Store the Everloop image in driver configuration
            driver_config_proto.image.led.extend(image)

            # Send driver configuration through ZMQ socket
            socket.send(driver_config_proto.SerializeToString())
            #Wait before restarting loop

            time.sleep(10)
            # Create a new driver config
            driver_config_proto = driver_pb2.DriverConfig()
            # Create an empty Everloop image
            image = []
            # For each device LED
            for led in range(ledCount):
                # Set individual LED value
                ledValue = io_pb2.LedValue()
                ledValue.blue = 10
                ledValue.red = 10
                ledValue.green = 10
                ledValue.white = 0
                image.append(ledValue)

            # Store the Everloop image in driver configuration
            driver_config_proto.image.led.extend(image)

            # Send driver configuration through ZMQ socket
            socket.send(driver_config_proto.SerializeToString())

            flag = False
Example #29
0
def construct_config_proto():
    driver_config_proto = driver_pb2.DriverConfig()
    driver_config_proto.delay_between_updates = 2.0
    driver_config_proto.timeout_after_last_ping = 6.0
    return driver_config_proto
Example #30
0
        # create hero
        hero = Hero(22)
        hero.vel = 0
        
        #create goal
        goal = Goal()
        goal.width = 4
        
        #for tracking time
        start_time = time.time()
        frame = 0
        
####################### led painting happens here ####################     
        while True:
            # Create a new driver config (for setup purposes)
            driver_config_proto = driver_pb2.DriverConfig()
            img.clear_all()
            
            # Painting obstacles
            img.set_led(int(lava.pos), int(lava.r),int(lava.g),int(lava.b),int(lava.w))
            img.set_led(int(lava1.pos), int(lava1.r),int(lava1.g),int(lava1.b),int(lava1.w))
            
            # Paint Goal
            for i_led, v_led in enumerate(goal.rgb_out()):
                img.set_led(int(goal.pos + i_led), int(v_led[0]), int(v_led[1]), int(v_led[2]), int(v_led[3]) )
            
            # Paint Hero
            img.set_led(int(hero.pos), int(hero.r),int(hero.g),int(hero.b),int(hero.w))
            
#####################################################################