def SetMasterStatusLed(self, state): Domoticz.Debug("SetMasterStatusLed - UID:" + self.UIDList[UIDINDEXMASTER]) try: # Create IP connection ipcon = IPConnection() # Create device object master = BrickMaster(self.UIDList[UIDINDEXMASTER], ipcon) # Connect to brickd ipcon.connect(Parameters["Address"], int(Parameters["Port"])) # Don't use device before ipcon is connected if state == 0: master.disable_status_led() Domoticz.Log("Master Status LED disabled.") if state == 1: master.enable_status_led() Domoticz.Log("Master Status LED enabled.") ipcon.disconnect() return 1 except: # Error Domoticz.Log("[ERROR] Can not set Master Status LED.") return 0
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: mb1.disable_status_led() mb2.disable_status_led() oled.write_line(3, 1, "Mode: Silent") else: mb1.enable_status_led() mb2.enable_status_led() oled.write_line(3, 1, "Mode: Debug") #***********Dual-Relay-Config*************************************** time.sleep(3) dr.set_state(False, False) oled.write_line(4, 1, "Dual Relay: OK") #***********Button-Config******************************************* time.sleep(10) rlb1.set_color(0, brightness, 0) # Tor oben
import time import confs from tinkerforge.ip_connection import IPConnection from tinkerforge.brick_master import BrickMaster from tinkerforge.bricklet_sound_pressure_level import BrickletSoundPressureLevel # Create IP connection ipcon = IPConnection() # bricks and bricklets master = BrickMaster(confs.MASTER_UID, ipcon) spl = BrickletSoundPressureLevel(confs.SOUND_UID, ipcon) # connect ipcon.connect(confs.HOST, confs.PORT) # turn on the leds master.enable_status_led() spl.set_status_led_config(1) # sleepa while time.sleep(10) # turn them off master.disable_status_led() spl.set_status_led_config(0) # when done dsiconnect ipcon.disconnect()
class WeatherStation: HOST = "localhost" PORT = 4223 ipcon = None lcd = None al_v2 = None hum_v2 = None baro = None master = None def __init__(self): self.ipcon = IPConnection() while True: try: self.ipcon.connect(WeatherStation.HOST, WeatherStation.PORT) break except Error as e: log.error('Connection Error: ' + str(e.description)) time.sleep(1) except socket.error as e: log.error('Socket error: ' + str(e)) time.sleep(1) self.ipcon.register_callback(IPConnection.CALLBACK_ENUMERATE, self.cb_enumerate) self.ipcon.register_callback(IPConnection.CALLBACK_CONNECTED, self.cb_connected) while True: try: self.ipcon.enumerate() break except Error as e: log.error('Enumerate Error: ' + str(e.description)) time.sleep(1) def cb_lcd_button_pressed(self, button): if self.lcd is not None: text = str(self.lcd.is_button_pressed(button)) log.debug('Button pressed ' + text) log.debug('It was button ' + str(button)) if button == 0: if self.lcd.is_backlight_on(): self.lcd.backlight_off() else: self.lcd.backlight_on() def cb_illuminance_v2(self, illuminance): if self.lcd is not None: text = 'Illuminanz %6.2f lx' % (illuminance/100.0) self.lcd.write_line(0, 0, text) log.debug('Write to line 0: ' + text) def cb_humidity_v2(self, humidity): if self.lcd is not None: text = 'Luftfeuchte %5.2f %%' % (humidity/100.0) self.lcd.write_line(1, 0, text) log.debug('Write to line 1: ' + text) try: temperature = self.hum_v2.get_temperature() except Error as e: log.error('Could not get temperature: ' + str(e.description)) return # \xDF == ° on LCD 20x4 charset text = 'Temperatur %6.2f \xDFC' % (temperature/100.0) self.lcd.write_line(3, 0, text) log.debug('Write to line 3: ' + text.replace('\xDF', '°')) def cb_air_pressure(self, air_pressure): if self.lcd is not None: text = 'Luftdruck %7.2f mb' % (air_pressure/1000.0) self.lcd.write_line(2, 0, text) log.debug('Write to line 2: ' + text) def cb_enumerate(self, uid, connected_uid, position, hardware_version, firmware_version, device_identifier, enumeration_type): if enumeration_type == IPConnection.ENUMERATION_TYPE_CONNECTED or \ enumeration_type == IPConnection.ENUMERATION_TYPE_AVAILABLE: if device_identifier == BrickletLCD20x4.DEVICE_IDENTIFIER: try: self.lcd = BrickletLCD20x4(uid, self.ipcon) self.lcd.clear_display() self.lcd.backlight_on() self.lcd.register_callback(self.lcd.CALLBACK_BUTTON_PRESSED, self.cb_lcd_button_pressed) log.info('LCD 20x4 initialized') except Error as e: log.error('LCD 20x4 init failed: ' + str(e.description)) self.lcd = None elif device_identifier == BrickletAmbientLightV2.DEVICE_IDENTIFIER: try: self.al_v2 = BrickletAmbientLightV2(uid, self.ipcon) self.al_v2.set_configuration(self.al_v2.ILLUMINANCE_RANGE_64000LUX, self.al_v2.INTEGRATION_TIME_200MS) self.al_v2.set_illuminance_callback_period(1000) self.al_v2.register_callback(self.al_v2.CALLBACK_ILLUMINANCE, self.cb_illuminance_v2) log.info('Ambient Light 2.0 initialized') except Error as e: log.error('Ambient Light 2.0 init failed: ' + str(e.description)) self.al_v2 = None elif device_identifier == BrickletHumidityV2.DEVICE_IDENTIFIER: try: self.hum_v2 = BrickletHumidityV2(uid, self.ipcon) self.hum_v2.set_humidity_callback_configuration(1000, True, 'x', 0, 0) self.hum_v2.register_callback(self.hum_v2.CALLBACK_HUMIDITY, self.cb_humidity_v2) log.info('Humidity 2.0 initialized') except Error as e: log.error('Humidity 2.0 init failed: ' + str(e.description)) self.hum_v2 = None elif device_identifier == BrickletBarometer.DEVICE_IDENTIFIER: try: self.baro = BrickletBarometer(uid, self.ipcon) self.baro.set_air_pressure_callback_period(1000) self.baro.register_callback(self.baro.CALLBACK_AIR_PRESSURE, self.cb_air_pressure) log.info('Barometer initialized') except Error as e: log.error('Barometer init failed: ' + str(e.description)) self.baro = None elif device_identifier == BrickMaster.DEVICE_IDENTIFIER: try: self.master = BrickMaster(uid, self.ipcon) self.master.disable_status_led() log.info('MasterBrick initialized') except Error as e: log.error('MasterBrick init failed: ' + str(e.description)) self.baro = None def cb_connected(self, connected_reason): if connected_reason == IPConnection.CONNECT_REASON_AUTO_RECONNECT: log.info('Auto Reconnect') while True: try: self.ipcon.enumerate() break except Error as e: log.error('Enumerate Error: ' + str(e.description)) time.sleep(1)
def InitBricks(self): Domoticz.Debug("InitBricks") try: # Create IP connection ipcon = IPConnection() # Create device objects master = BrickMaster(self.UIDList[UIDINDEXMASTER], ipcon) rl = BrickletRGBLEDV2(self.UIDList[UIDINDEXRGBLED], ipcon) aq = BrickletAirQuality(self.UIDList[UIDINDEXAIRQUALITY], ipcon) lcd = BrickletLCD20x4(self.UIDList[UIDINDEXLCD], ipcon) # Connect to brickd ipcon.connect(Parameters["Address"], int(Parameters["Port"])) # Settings ## Master - Turn status led off master.disable_status_led() Domoticz.Log("Master Status LED disabled.") ## RGB LED - Turn status led off rl.set_status_led_config(0) Domoticz.Log("RGB LED Status LED disabled.") ## Air Quality - Config ## Turn off status led aq.set_status_led_config(0) Domoticz.Log("Air Quality Status LED disabled.") # Set temperature offset with resolution 1/100°C. Offset 10 = decrease measured temperature by 0.1°C, 100 = 1°C. # offset - int # Test with 2°C = 200 aq.set_temperature_offset(200) # The Air Quality Bricklet uses an automatic background calibration mechanism to calculate the IAQ Index. # This calibration mechanism considers a history of measured data. Duration history = 4 days (0) or 28 days (1). # duration - int 0 | 1 # Test with 0 = 4 days aq.set_background_calibration_duration(0) ## LCD - Turn backlight ON (ensure to update the domoticz switch device), set initial welcome text. lcd.backlight_on() Devices[UNITSWITCHBACKLIGHT].Update(nValue=1, sValue=str(0)) SetLCDText(self, "Indoor Air Quality", "Station " + PLUGINVERSION, "", "2019 by rwbl") # Disconnect and return OK ipcon.disconnect() Domoticz.Debug("InitBricks OK") self.isError = 0 return 1 except: # Error self.isError = 1 Domoticz.Log("[ERROR] Can not init the bricks.") return 0 return