Beispiel #1
0
def on_message(client, userdata, message):
    if message.topic != Config.server_topic:
        return

    global DoNotExit
    if not DoNotExit:
        return

    try:
        j = json.loads(str(message.payload.decode("utf-8")))

        device_mac = str(Config.dotti_mac)
        if "mac" in j:
            device_mac = str(j["mac"])

        mode = str(j["mode"])
        color = [0, 0, 0]
        if mode == "color" and "color" in j:
            color = ast.literal_eval(str(j["color"]))

        if DoNotExit and mode == "exit":
            DoNotExit = False
            return

        if mode != "hour" and mode != "color":
            print("ERROR - unknown mode=" + mode)
            return

        dotti = Dotti(device_mac)
        dotti.mode(mode, color)

    except ValueError:
        logger.error("decoding house/dotti payload failed !")
    except:
        logger.error("processing house/dotti payload failed !")
Beispiel #2
0
def mqtt_listeners():
    for d in devices.KNOWN_DEVICES:
        x = None
        if d['sensor'] == Dotti.name:
            x = Dotti(d['mac'])

        if x is not None:
            topic = MqttConfig.server_topic + d['sensor'] + '/' + d['name']
            logger.debug('subscribe to ' + topic)
            client.subscribe(topic)

            mqtt_topic_handle[topic] = x.handle_message
Beispiel #3
0
    42: red,
    44: red,
    45: red,
    47: red,
    51: red,
    53: red,
    54: red,
    60: red,
    61: red
}

if __name__ == '__main__':
    device_addr = '5C:31:3E:89:8F:F2'
    if len(sys.argv) > 1:
        device_addr = sys.argv[1]

    with Dotti(device_addr, None, True) as dotti:

        print("Connected to device: {}".format(device_addr))
        print("Sample 5 running")

        dotti.setColor((0, 0, 0))

        for px, color in raspi.iteritems():
            dotti.setPixelColor(px, color)
            time.sleep(0.05)

    print("Disconnected from device")
    print("Goodbye!")
    exit()
Beispiel #4
0
#!/usr/bin/env python2.7

import sys, select, os, time, random
from dotti import Dotti

if __name__ == '__main__':
    device_addr = '5C:31:3E:89:8F:F2'
    if len(sys.argv) > 1:
        device_addr = sys.argv[1]

    dotti = Dotti(device_addr)
    dotti.connect()

    print("Connected to device: {}".format(device_addr))
    print("Sample 6 running")
    print("Press enter to exit")
    dotti.setColor((0, 0, 0))

    while True:
        level = random.randrange(7)
        red = random.randrange(256)
        green = random.randrange(256)
        blue = random.randrange(256)
        dotti.setBarLevel(level + 1, (red, green, blue))
        delay = random.randrange(50)
        time.sleep(0.45 + (1 / (delay + 1)))
        if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
            line = raw_input()
            break

    dotti.disconnect()
Beispiel #5
0
#!/usr/bin/env python2.7

import sys, select, os, time, random
import bluepy
import bluepy.btle as btle
from dotti import Dotti

if __name__ == '__main__':
    device_addr = '5C:31:3E:89:8F:F2'
    if len(sys.argv) > 1:
        device_addr = sys.argv[1]

    dotti = Dotti(device_addr)
    dotti.connect()

    print("Connected to device: {}".format(device_addr))
    print("Random coloring sequence")
    print("Press enter to exit")
    while True:

        #Turn on random led pixel
        pixel = random.randrange(64)
        red = random.randrange(256)
        green = random.randrange(256)
        blue = random.randrange(256)
        color = (red, green, blue)
        dotti.setPixelColor(pixel + 1, color)
        time.sleep(0.05)

        #Turn off random led pixel
        pixel = random.randrange(64)
Beispiel #6
0
#!/usr/bin/env python2.7

from picamera.array import PiRGBArray
from picamera import PiCamera
from dotti import Dotti
import cv2, time, sys, select


with Dotti('5C:31:3E:89:8F:F2', None, True) as dotti:
    dotti.setColor((0,0,0))
    
    #Load a cascade file for detecting faces
    face_cascade = cv2.CascadeClassifier('/usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml')
    #Get the picture (low resolution, so it should be quite fast)
    resolution = (320, 240)

    print("Press {enter} to exit")
    
    with PiCamera(resolution=resolution, framerate=32) as camera:
        rawCapture = PiRGBArray(camera, size=resolution)
        for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
            image = frame.array
            #Convert to grayscale
            gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
            #Look for faces in the image using the loaded cascade file
            faces = face_cascade.detectMultiScale(gray, 1.1, 5)
            #Truncate the stream for next iteration
            rawCapture.truncate(0)

            #Dotti logic to display the icon 
            if len(faces) > 0:                
Beispiel #7
0
#!/usr/bin/env python2.7

import sys, select, os, time, random
import bluepy
import bluepy.btle as btle
from dotti import Dotti

if __name__ == '__main__':
    device_addr = '5C:31:3E:89:8F:F2'
    if len(sys.argv) > 1:
        device_addr = sys.argv[1]

    dotti = Dotti(device_addr)
    dotti.connect()

    print("Connected to device: {}".format(device_addr))
    print("Sample 4 running")
    dotti.setColor((0, 0, 0))
    for n in range(3):
        dotti.setIcon(5)
        time.sleep(1)
        dotti.setColor((0, 0, 0))
        time.sleep(1)

    dotti.disconnect()
    print("Disconnected from device")
    print("Goodbye!")
    exit()
Beispiel #8
0
#!/usr/bin/env python2.7

import sys, select, os, time, random
import bluepy
import bluepy.btle as btle
from dotti import Dotti

black = (0, 0, 0)

if __name__ == '__main__':
    device_addr = '5C:31:3E:89:8F:F2'
    if len(sys.argv) > 1:
        device_addr = sys.argv[1]

    dotti = Dotti(device_addr)
    dotti.connect()

    print("Connected to device: {}".format(device_addr))
    print("Sample 2 running")
    dotti.setColor(black)
    for n in range(4):
        for pixel in range(64):
            red = random.randrange(255 if n == 1 else (1 * (pixel + 1)))
            green = random.randrange(255 if n == 2 else (1 * (pixel + 1)))
            blue = random.randrange(255 if n == 3 else (1 * (pixel + 1)))
            color = (red, green, blue)
            dotti.setPixelColor(pixel + 1, color)
            time.sleep(0.05)
    dotti.disconnect()
    print("Disconnected from device")
    print("Goodbye!")