예제 #1
0
class PowerSupply:
    def __init__(self, ipcon: IPConnection, UID):
        self.dRelay = BrickletDualRelay(UID, ipcon)

    def enable(self):
        self.dRelay.set_state(True, True)

    def disable(self):
        self.dRelay.set_state(False, False)
예제 #2
0
def switchOFFmotor():
    import time

    from tinkerforge.ip_connection import IPConnection
    from tinkerforge.bricklet_dual_relay import BrickletDualRelay

    HOST = "192.168.1.103"
    PORT = 4223
    UID = "Aci"  # Change XYZ to the UID of your Dual Relay Bricklet

    ipcon = IPConnection()  # Create IP connection
    dr = BrickletDualRelay(UID, ipcon)  # Create device object

    ipcon.connect(HOST, PORT)  # Connect to brickd
    # Don't use device before ipcon is connected

    print dr.get_state()
    time.sleep(0.5)
    dr.set_state(False, False)
    time.sleep(0.5)
    print dr.get_state()
    ipcon.disconnect()
예제 #3
0
def findDeviceType(id, devicetype):
    global ipcon
    tmp = hal.Devices.find(id)
    if tmp != None:
        return tmp.Device
    else:
        if devicetype == 13: return BrickMaster(id, ipcon)
        elif devicetype == 14: return BrickServo(id, ipcon)
        elif devicetype == 227: return BrickletVoltageCurrent(id, ipcon)
        elif devicetype == 2105: return BrickletVoltageCurrentV2(id, ipcon)
        elif devicetype == 100: return BrickletIO16(id, ipcon)
        elif devicetype == 243: return BrickletColor(id, ipcon)
        elif devicetype == 2128: return BrickletColorV2(id, ipcon)
        elif devicetype == 26: return BrickletDualRelay(id, ipcon)
        elif devicetype == 284: return BrickletIndustrialDualRelay(id, ipcon)
        elif devicetype == 225: return BrickletIndustrialQuadRelay(id, ipcon)
        elif devicetype == 2102:
            return BrickletIndustrialQuadRelayV2(id, ipcon)
        else:
            print("Warning: DeviceType " + str(devicetype) + " not found")
            return None
예제 #4
0
            activCH2 = False
        if activCH2 == True:
            dr.set_selected_state(2, False)
            oled.write_line(3, 0, "Beleuchtung:      AUS")
            rlb2.set_color(brightness, 0, 0)
        else:
            dr.set_selected_state(2, True)
            oled.write_line(3, 0, "Beleuchtung:      EIN")
            rlb2.set_color(0, brightness, 0)


if __name__ == "__main__":
    time.sleep(10)
    ipcon = IPConnection()  # Create IP connection
    rtc = BrickletRealTimeClock(UID_RTC, ipcon)  # Create device object
    dr = BrickletDualRelay(UID_DR, ipcon)  # Create device object
    rlb1 = BrickletRGBLEDButton(UID_RLB_1, ipcon)  # Create device object
    rlb2 = BrickletRGBLEDButton(UID_RLB_2, ipcon)  # Create device object
    oled = BrickletOLED128x64(UID_OLED, ipcon)  # Create device object
    temp = BrickletTemperature(UID_TEMP, ipcon)  # Create device object
    mb1 = BrickMaster(UID_MB1, ipcon)  # Create device object
    mb2 = BrickMaster(UID_MB2, ipcon)  # Create device object

    ipcon.connect(HOST, PORT)  # Connect to brickd
    # Don't use device before ipcon is connected
    time.sleep(1)
    oled.clear_display()
    oled.write_line(1, 1, "Starting Application...")

    #***********Brick-Config********************************************
    if silent == True:
예제 #5
0
 def __init__(self, ipcon: IPConnection, UID):
     self.dRelay = BrickletDualRelay(UID, ipcon)
#!/usr/bin/env python
# -*- coding: utf-8 -*-

HOST = "localhost"
PORT = 4223
UID = "XYZ" # Change XYZ to the UID of your Dual Relay Bricklet

import time

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_dual_relay import BrickletDualRelay

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    dr = BrickletDualRelay(UID, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    # Turn relays alternating on/off 10 times with 1 second delay
    for i in range(5):
        time.sleep(1)
        dr.set_state(True, False)
        time.sleep(1)
        dr.set_state(False, True)

    raw_input("Press key to exit\n") # Use input() in Python 3
    ipcon.disconnect()
예제 #7
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

HOST = "192.168.1.103"
PORT = 4223
UID = "Aci" # Change XYZ to the UID of your Dual Relay Bricklet

import time

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_dual_relay import BrickletDualRelay

if __name__ == "__main__":
    	ipcon = IPConnection() # Create IP connection
    	dr = BrickletDualRelay(UID, ipcon) # Create device object

    	ipcon.connect(HOST, PORT) # Connect to brickd
    	# Don't use device before ipcon is connected

	print dr.get_state()
        time.sleep(0.5)
        dr.set_state(False, False)
	time.sleep(0.5)
	print dr.get_state()
   	ipcon.disconnect()
예제 #8
0
    def cb_enumerate(cls, uid, connected_uid, position, hardware_version,
                     firmware_version, device_identifier, enumeration_type):
        #global self.led
        found = False
        if enumeration_type == IPConnection.ENUMERATION_TYPE_CONNECTED or \
           enumeration_type == IPConnection.ENUMERATION_TYPE_AVAILABLE:
            # Enumeration for LED
            if device_identifier == LEDStrip.DEVICE_IDENTIFIER:
                cls.LEDs.append(LEDStrip(uid, cls.ipcon))
                temp_uid = str(cls.LEDs[-1].get_identity()[1]) + "." + str(
                    cls.LEDs[-1].get_identity()[0])
                cls.LEDList.addLED(cls.LEDs[-1], temp_uid)
                cls.LEDs[-1].set_frame_duration(200)
                if settings.LEDs.get(temp_uid) <> None:
                    cls.LEDs[-1].set_chip_type(settings.LEDs.get(temp_uid)[0])
                    cls.LEDs[-1].set_frame_duration(
                        settings.LEDs.get(temp_uid)[1])
                    found = True
                #self.led.register_callback(self.led.CALLBACK_FRAME_RENDERED,
                #                lambda x: __cb_frame_rendered__(self.led, x))
                #self.led.set_rgb_values(0, self.NUM_LEDS, self.r, self.g, self.b)
                #self.led.set_rgb_values(15, self.NUM_LEDS, self.r, self.g, self.b)
                #self.led.set_rgb_values(30, self.NUM_LEDS, self.r, self.g, self.b)

            if device_identifier == IO16.DEVICE_IDENTIFIER:
                cls.io.append(IO16(uid, cls.ipcon))
                temp_uid = str(cls.io[-1].get_identity()[1]) + "." + str(
                    cls.io[-1].get_identity()[0])
                cls.io16list.addIO(cls.io[-1], temp_uid, 16)
                cls.io[-1].set_debounce_period(100)
                if settings.IO16.get(temp_uid) <> None:
                    cls.io[-1].set_port_interrupt(
                        'a',
                        settings.IO16.get(temp_uid)[0])
                    cls.io[-1].set_port_interrupt(
                        'b',
                        settings.IO16.get(temp_uid)[1])
                    cls.io[-1].set_port_configuration(
                        'a',
                        settings.IO16.get(temp_uid)[0], 'i', True)
                    cls.io[-1].set_port_configuration(
                        'b',
                        settings.IO16.get(temp_uid)[1], 'i', True)
                    cls.io[-1].set_port_configuration(
                        'a',
                        settings.IO16.get(temp_uid)[2], 'o', False)
                    cls.io[-1].set_port_configuration(
                        'b',
                        settings.IO16.get(temp_uid)[3], 'o', False)
                    #self.io[-1].set_port_monoflop('a', tifo_config.IO16.get(temp_uid)[4],0,tifo_config.IO16.get(temp_uid)[6])
                    #self.io[-1].set_port_monoflop('b', tifo_config.IO16.get(temp_uid)[5],0,tifo_config.IO16.get(temp_uid)[6])
                    cls.io[-1].register_callback(
                        cls.io[-1].CALLBACK_INTERRUPT,
                        partial(cls.cb_interrupt,
                                device=cls.io[-1],
                                uid=temp_uid))
                    found = True

            if device_identifier == AmbientLight.DEVICE_IDENTIFIER:
                cls.al.append(AmbientLight(uid, cls.ipcon))
                cls.al[-1].set_illuminance_callback_threshold('o', 0, 0)
                cls.al[-1].set_debounce_period(10)
                #self.al.set_illuminance_callback_threshold('<', 30, 30)
                #self.al.set_analog_value_callback_period(10000)
                #self.al.set_illuminance_callback_period(10000)
                #self.al.register_callback(self.al.CALLBACK_ILLUMINANCE, self.cb_ambLight)
                #self.al.register_callback(self.al.CALLBACK_ILLUMINANCE_REACHED, self.cb_ambLight)
                args = cls.al[-1]
                #self.al[-1].register_callback(self.al[-1].CALLBACK_ILLUMINANCE_REACHED, lambda event1, event2, event3, args=args: self.cb_ambLight(event1, event2, event3, args))

                cls.al[-1].register_callback(
                    cls.al[-1].CALLBACK_ILLUMINANCE_REACHED,
                    partial(cls.cb_ambLight, device=args))
                temp_uid = str(cls.al[-1].get_identity()[1]) + "." + str(
                    cls.al[-1].get_identity()[0])

                thread_cb_amb = Timer(60, cls.thread_ambLight, [cls.al[-1]])
                thread_cb_amb.start()

            if device_identifier == BrickletCO2.DEVICE_IDENTIFIER:
                cls.co2.append(BrickletCO2(uid, cls.ipcon))
                temp_uid = str(cls.co2[-1].get_identity()[1]) + "." + str(
                    cls.co2[-1].get_identity()[0])
                thread_co2_ = Timer(5, cls.thread_CO2, [cls.co2[-1]])
                thread_co2_.start()
                cls.threadliste.append(thread_co2_)

            if device_identifier == BrickletDualRelay.DEVICE_IDENTIFIER:
                cls.drb.append(BrickletDualRelay(uid, cls.ipcon))


#
#            if device_identifier == Moisture.DEVICE_IDENTIFIER:
#                self.moist = Moisture(uid, self.ipcon)
#                self.moist.set_moisture_callback_period(10000)
#                self.moist.register_callback(self.moist.CALLBACK_MOISTURE, self.cb_moisture)

            if device_identifier == BrickletMotionDetector.DEVICE_IDENTIFIER:
                cls.md.append(BrickletMotionDetector(uid, cls.ipcon))
                temp_uid = str(cls.md[-1].get_identity()[1]) + "." + str(
                    cls.md[-1].get_identity()[0])
                cls.md[-1].register_callback(
                    cls.md[-1].CALLBACK_MOTION_DETECTED,
                    partial(cls.cb_md, device=cls.md[-1], uid=temp_uid))
                cls.md[-1].register_callback(
                    cls.md[-1].CALLBACK_DETECTION_CYCLE_ENDED,
                    partial(cls.cb_md_end, device=cls.md[-1], uid=temp_uid))

            if device_identifier == BrickletSoundIntensity.DEVICE_IDENTIFIER:
                cls.si.append(BrickletSoundIntensity(uid, cls.ipcon))
                temp_uid = str(cls.si[-1].get_identity()[1]) + "." + str(
                    cls.si[-1].get_identity()[0])

                cls.si[-1].set_debounce_period(1000)
                cls.si[-1].register_callback(
                    cls.si[-1].CALLBACK_INTENSITY_REACHED,
                    partial(cls.cb_si, device=cls.si[-1], uid=temp_uid))
                cls.si[-1].set_intensity_callback_threshold('>', 200, 0)

            if device_identifier == BrickletPTC.DEVICE_IDENTIFIER:
                cls.ptc.append(BrickletPTC(uid, cls.ipcon))
                temp_uid = str(cls.ptc[-1].get_identity()[1]) + "." + str(
                    cls.ptc[-1].get_identity()[0])
                thread_pt_ = Timer(5, cls.thread_pt, [cls.ptc[-1]])
                thread_pt_.start()
                cls.threadliste.append(thread_pt_)

            if device_identifier == BrickletTemperature.DEVICE_IDENTIFIER:
                cls.temp.append(BrickletTemperature(uid, cls.ipcon))
                temp_uid = str(cls.temp[-1].get_identity()[1]) + "." + str(
                    cls.temp[-1].get_identity()[0])
                thread_pt_ = Timer(5, cls.thread_pt, [cls.temp[-1]])
                thread_pt_.start()
                cls.threadliste.append(thread_pt_)

            if device_identifier == BrickMaster.DEVICE_IDENTIFIER:
                cls.master.append(BrickMaster(uid, cls.ipcon))
                thread_rs_error = Timer(60, cls.thread_RSerror, [])
                #thread_rs_error.start()
                if settings.inputs.get(uid) <> None:
                    found = True

            if not found:
                toolbox.log(connected_uid, uid, device_identifier)
                print connected_uid, uid, device_identifier
예제 #9
0
import socketio

HOST = "localhost"
PORT = 4223
UID = "xpN"  # UID of Distance IR Bricklet
UID_dual_button = "mMX"
UID_dual_relay = "E8x"
UID_oled = "yqA"

isObjectPresent = False
objCount = 0

ipcon = IPConnection()  # Create IP connection
dir = BrickletDistanceIR(UID, ipcon)  # Create device object
db = BrickletDualButton(UID_dual_button, ipcon)
m_relay = BrickletDualRelay(UID_dual_relay, ipcon)  # Create device object
display = BrickletOLED128x64(UID_oled, ipcon)
pygame.mixer.init(44100, -16, 2, 1024)
sound = pygame.mixer.Sound('laser.wav')
denied_sound = pygame.mixer.Sound('denied.wav')
backend_connected = False
user_logged_in = False
user_name = ""
last_object = ""


def timeout():
    global isObjectPresent
    timer.cancel()
    if isObjectPresent:
        print("object out")