Exemplo n.º 1
0
from tinkerforge.bricklet_sound_intensity import SoundIntensity
from tinkerforge.bricklet_dust_detector import DustDetector
from tinkerforge.bricklet_temperature import Temperature
from tinkerforge.bricklet_ambient_light import AmbientLight
from tinkerforge.bricklet_uv_light import BrickletUVLight
from tinkerforge.bricklet_motion_detector import BrickletMotionDetector
from tinkerforge.bricklet_humidity_v2 import HumidityV2

import time
from datetime import datetime

if __name__ == "__main__":
    ipcon = IPConnection()  # Create IP connection
    co2 = BrickletCO2(CO2_UID, ipcon)  # Create device object
    humidity = HumidityV2(HUMIDITY_UID, ipcon)
    sound_intensity = SoundIntensity(SOUND_INTENSITY_UID, ipcon)
    dust_density = DustDetector(DUST_UID, ipcon)
    temperature = Temperature(TEMPERATURE_UID, ipcon)
    ambientlight = AmbientLight(AMBIENTLIGHT_UID, ipcon)
    uvlight = BrickletUVLight(UVLIGHT_UID, ipcon)
    motiondetect = BrickletMotionDetector(MOTIONDETECTOR_UID, ipcon)

    ipcon.connect(HOST, PORT)  # Connect to brickd

    while (True):
        curtime = datetime.now()
        print("Time: " + curtime.strftime('%Y/%m/%d %H:%M:%S'))

        motion = motiondetect.get_motion_detected()
        print("Motion: " + str(motion))
Exemplo n.º 2
0
    def cb_enumerate(self, uid, connected_uid, position, hardware_version,
                     firmware_version, device_identifier, enumeration_type):
        """Recherche des brickets et configuration."""

        if enumeration_type == IPConnection.ENUMERATION_TYPE_CONNECTED or \
           enumeration_type == IPConnection.ENUMERATION_TYPE_AVAILABLE:
            if device_identifier == Temperature.DEVICE_IDENTIFIER:
                try:
                    self.temp = Temperature(uid, self.ipcon)
                    log.info(
                        time.strftime("%Y-%m-%d %H:%M:%S") +
                        ' Temperature initialized')
                except Error as err:
                    log.error(
                        time.strftime("%Y-%m-%d %H:%M:%S") +
                        ' Temperature init failed: ' + str(err.description))
                    self.temp = None
            elif device_identifier == SoundIntensity.DEVICE_IDENTIFIER:
                try:
                    self.sound = SoundIntensity(uid, self.ipcon)
                    log.info(
                        time.strftime("%Y-%m-%d %H:%M:%S") +
                        ' Sound intensity initialized')
                except Error as err:
                    log.error(
                        time.strftime("%Y-%m-%d %H:%M:%S") +
                        ' Sound intensity init failed: ' +
                        str(err.description))
                    self.sound = None
            elif device_identifier == Accelerometer.DEVICE_IDENTIFIER:
                try:
                    self.accel = Accelerometer(uid, self.ipcon)
                    log.info(
                        time.strftime("%Y-%m-%d %H:%M:%S") +
                        ' Accelerometer initialized')
                except Error as err:
                    log.error(
                        time.strftime("%Y-%m-%d %H:%M:%S") +
                        ' Accelerometer init failed: ' + str(err.description))
                    self.accel = None
            elif device_identifier == IndustrialAnalogOut.DEVICE_IDENTIFIER:
                try:
                    self.aout = IndustrialAnalogOut(uid, self.ipcon)
                    self.aout.set_configuration(
                        self.aout.VOLTAGE_RANGE_0_TO_5V,
                        self.aout.CURRENT_RANGE_0_TO_20MA)
                    self.aout.enable()
                    self.aout_connected = True
                    log.info(
                        time.strftime("%Y-%m-%d %H:%M:%S") +
                        ' IndustrialAnalogOut initialized')
                except Error as err:
                    log.error(
                        time.strftime("%Y-%m-%d %H:%M:%S") +
                        ' IndustrialAnalogOut init failed: ' +
                        str(err.description))
                    self.aout = None
            elif device_identifier == IndustrialDualAnalogIn.DEVICE_IDENTIFIER:
                try:
                    self.ain = IndustrialDualAnalogIn(uid, self.ipcon)
                    self.ain.set_sample_rate(6)
                    self.ain_connected = True
                    log.info(
                        time.strftime("%Y-%m-%d %H:%M:%S") +
                        ' IndustrialDualAnalogIn initialized')
                except Error as err:
                    log.error(
                        time.strftime("%Y-%m-%d %H:%M:%S") +
                        ' IndustrialDualAnalogIn init failed: ' +
                        str(err.description))
                    self.ain = None
            elif device_identifier == IndustrialDigitalIn4.DEVICE_IDENTIFIER:
                try:
                    self.din = IndustrialDigitalIn4(uid, self.ipcon)
                    self.din.set_interrupt(8)
                    self.din.set_debounce_period(0)
                    self.din.register_callback(self.din.CALLBACK_INTERRUPT,
                                               self.cb_compteur_turbine)
                    self.din_connected = True
                    log.info(
                        time.strftime("%Y-%m-%d %H:%M:%S") +
                        ' IndustrialDigitalIn4 initialized')
                except Error as err:
                    log.error(
                        time.strftime("%Y-%m-%d %H:%M:%S") +
                        ' IndustrialDigitalIn4 init failed: ' +
                        str(err.description))
                    self.din = None