def relay_flash(baudrate, tty, firmware, uid_iqr, uid_master): ipcon = IPConnection() iqr = BrickletIndustrialQuadRelay(uid_iqr, ipcon) master = BrickMaster(uid_master, ipcon) ipcon.connect('localhost', 4223) # reset_usb() # time.sleep(1) i = 10 while True: if i == 10: master.get_chibi_error_log() iqr.set_value(MASK_DATA) time.sleep(0.2) iqr.set_value(MASK_POWER | MASK_DATA) i = 0 i += 1 try: time.sleep(0.01) xmc_flash(baudrate, tty, firmware) break except Exception as e: print(str(e)) iqr.set_value(MASK_POWER) master.reset() ipcon.disconnect()
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
def __init__(self, _): self.ipcon = IPConnection() # Create IP connection self.master = BrickMaster(UID, self.ipcon) # Create device object self.ipcon.connect(HOST, PORT) self.timeout = 1 self.read_buffer = [] self.baudrate = None time.sleep(1)
def main(host, port, uid_rs485, uid_master): ipcon = IPConnection() rs485 = BrickletRS485(uid_rs485, ipcon) master = BrickMaster(uid_master, ipcon) ipcon.connect(host, port) print("get: " + str(rs485.get_bootloader_mode())) print("set 1: " + str(rs485.set_bootloader_mode(1)))
def main(host, port, uid_rs485, uid_master): ipcon = IPConnection() rs485 = BrickletRS485(uid_rs485, ipcon) master = BrickMaster(uid_master, ipcon) ipcon.connect(host, port) print('Baudrate before: ' + str(master.get_spitfp_baudrate('c'))) master.set_spitfp_baudrate('c', 2000000) print('Baudrate after: ' + str(master.get_spitfp_baudrate('c')))
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 print_master(conn, settings, uid): from tinkerforge.brick_master import BrickMaster # type: ignore[import] # pylint: disable=import-error,import-outside-toplevel br = BrickMaster(uid, conn) print_generic( settings, "master", br.get_identity(), 1.0, "", br.get_stack_voltage(), br.get_stack_current(), br.get_chip_temperature(), )
def print_master(conn, settings, uid): from tinkerforge.brick_master import BrickMaster # type: ignore[import] br = BrickMaster(uid, conn) print_generic( settings, "master", br.get_identity(), 1.0, "", br.get_stack_voltage(), br.get_stack_current(), br.get_chip_temperature(), )
def main(host, port, uid1, uid2, uid3, uid_master): ipcon = IPConnection() rs4851 = BrickletRS485(uid1, ipcon) rs4852 = BrickletRS485(uid2, ipcon) rs4853 = BrickletRS485(uid3, ipcon) master = BrickMaster(uid_master, ipcon) ipcon.connect(host, port) while True: print('RS485-1: ' + str(rs4851.get_spitfp_error_count())) print('RS485-2: ' + str(rs4852.get_spitfp_error_count())) print('RS485-3: ' + str(rs4853.get_spitfp_error_count())) print('Master-a: ' + str(master.get_spitfp_error_count('a'))) print('Master-b: ' + str(master.get_spitfp_error_count('b'))) print('Master-c: ' + str(master.get_spitfp_error_count('c'))) time.sleep(1)
def __init__(self): # Attribute importiert self.__UIDmaster = matrixProperties.UIDmaster # "6et15y" self.__UIDbricklet = matrixProperties.UIDbricklet # "wVj" self.__HOST = matrixProperties.HOST # "localhost" self.__PORT = matrixProperties.PORT # 4223 self.__matrixIndexRed = matrixProperties.IndexRed # 0 self.__matrixIndexGreen = matrixProperties.IndexGreen # 1 self.__matrixIndexBlue = matrixProperties.IndexBlue # 2 self.__rows = matrixProperties.ROWS # 10 self.__columns = matrixProperties.COLUMNS # 20 self.__LEDnr = matrixProperties.LEDnr # Liste LED-Nummern 0 bis 199 self.__numLEDS = matrixProperties.NUM_LEDS # 16 self.__rgb = [[0 for i in range(self.__numLEDS)] for i in range(3)] # RGB-Array self.__image = matrixProperties.defaultImage # Default-Bild setzen self.__imageIndexRed = 0 self.__imageIndexGreen = 1 self.__imageIndexBlue = 2 # Instanzvariablen self.__light = True # Boolean: True / False # Objekte print("Instanz LEDmatrix wurde erstellt.") self.__ipcon = IPConnection() # Create IP connection self.__masterBrick = BrickMaster(self.__UIDmaster, self.__ipcon) self.__brickletLEDstrip = BrickletLEDStrip( self.__UIDbricklet, self.__ipcon) # Create device object # Connect to brickd --> Verbindung Masterbrick? richtiger RGB-Kanal einstellen? self.__ipcon.connect(self.__HOST, self.__PORT) print("Verbindung zu brickd hergestellt.") self.__brickletLEDstrip.set_frame_duration( 20) # Anzeigedauer Bild: 20ms ergibt 20 Bilder pro Sekunde self.__brickletLEDstrip.set_channel_mapping( self.__brickletLEDstrip.CHANNEL_MAPPING_RGB ) # CHANNEL_MAPPING_RGB = 6 -> Farbkanal definieren (RGB statt BGR) # Callback starten self.__brickletLEDstrip.register_callback( self.__brickletLEDstrip.CALLBACK_FRAME_RENDERED, lambda x: self.__loadPicture__()) print("Callback aktiviert.")
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
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
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: mb1.disable_status_led() mb2.disable_status_led() oled.write_line(3, 1, "Mode: Silent") else: mb1.enable_status_led()
""" turn off the leds on the sensors / bricks on restart """ 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
def onHeartbeat(self): self.HeartbeatCounter = self.HeartbeatCounter + 1 Domoticz.Debug("onHeartbeat called. Counter=" + str(self.HeartbeatCounter * self.HeartbeatInterval) + " (Heartbeat=" + Parameters["Mode5"] + ")") # Reset ipconnected flag self.ipConnected = 0 # check the heartbeatcounter against the heartbeatinterval if (self.HeartbeatCounter * self.HeartbeatInterval) % int( Parameters["Mode5"]) == 0: try: # Create IP connection ipcon = IPConnection() Domoticz.Debug("IP Connected created") # Create the device objects master = BrickMaster(self.UIDList[UIDINDEXMASTER], ipcon) aq = BrickletAirQuality(self.UIDList[UIDINDEXAIRQUALITY], ipcon) lcd = BrickletLCD20x4(self.UIDList[UIDINDEXLCD], ipcon) rl = BrickletRGBLEDV2(self.UIDList[UIDINDEXRGBLED], ipcon) al = BrickletAmbientLightV2(self.UIDList[UIDINDEXAMBIENTLIGHT], ipcon) Domoticz.Debug("Devices created - OK") # Connect to brickd using Host and Port try: ipcon.connect(Parameters["Address"], int(Parameters["Port"])) self.ipConnected = 1 Domoticz.Debug("IP Connection - OK") except: self.isError = 1 Domoticz.Debug("[ERROR] IP Connection failed") # Don't use device before ipcon is connected # Set Alert Indicator to Orange with ERROR text if self.ipConnected == 0: ## Alert device (5)nvalue=LEVEL - (0=gray, 1=green, 2=yellow, 3=orange, 4=red),svalue=TEXT # Devices[ALERTDEVICE].Update( nValue=3, sValue="ERROR") #Domoticz.Debug(Devices[ALERTDEVICE].Name + "-nValue=" + str(Devices[ALERTDEVICE].nValue) + ",sValue=" + Devices[ALERTDEVICE].sValue ) Devices[UNITTEXTSTATUS].Update( nValue=0, sValue= "[ERROR] Can not connect to the Master Brick. Check device or settings." ) Domoticz.Log(Devices[UNITTEXTSTATUS].sValue) self.isError = 1 return # If there was an error in the connection,init the bricks again if self.isError == 1 and self.ipConnected == 1: InitBricks(self) self.isError = 0 # AIR QUALITY # Get current all values iaq_index, iaq_index_accuracy, temperature, humidity, air_pressure = aq.get_all_values( ) ## TESTdata with using the air quality bricklet ''' iaq_index = 69 # 0 -200 iaq_index_accuracy = 21 temperature = 2432 humidity = 6894 air_pressure = 102412 ''' # Update the devices # IAQ (Indoor Air Quality) Index ## nValue=0 ## sValue=string value Devices[UNITAIRQUALITYIAQINDEX].Update(nValue=0, sValue=str(iaq_index)) # Devices[UNITAIRQUALITYIAQINDEX].Update( nValue=iaq_index, sValue="0") Domoticz.Debug(Devices[UNITAIRQUALITYIAQINDEX].Name + "-IAQ Index:" + str(iaq_index)) # IAQ Index Accuracy ## nvalue=LEVEL - (0=gray, 1=green, 2=yellow, 3=orange, 4=red) ## svalue=TEXT iaqaccuracylevel = 0 if iaq_index_accuracy == aq.ACCURACY_UNRELIABLE: iaqaccuracylevel = 4 elif iaq_index_accuracy == aq.ACCURACY_LOW: iaqaccuracylevel = 3 elif iaq_index_accuracy == aq.ACCURACY_MEDIUM: iaqaccuracylevel = 2 elif iaq_index_accuracy == aq.ACCURACY_HIGH: iaqaccuracylevel = 1 iaqaccuracytext = AIRQUALITYACCURACY[iaqaccuracylevel] Devices[UNITALERTIAQINDEXACCURACY].Update( nValue=iaqaccuracylevel, sValue=iaqaccuracytext) Domoticz.Debug(Devices[UNITALERTIAQINDEXACCURACY].Name + "-IAQ IndexAccuracy:" + str(iaqaccuracylevel) + "," + iaqaccuracytext) # Air Quality ## nvalue=LEVEL - see xml definition ## svalue=TEXT airqualitylevel = 0 if iaq_index >= 0 and iaq_index <= AIRQUALITYLEVELLIMIT[1]: airqualitylevel = 1 if iaq_index > AIRQUALITYLEVELLIMIT[ 1] and iaq_index <= AIRQUALITYLEVELLIMIT[2]: airqualitylevel = 2 if iaq_index > AIRQUALITYLEVELLIMIT[ 2] and iaq_index <= AIRQUALITYLEVELLIMIT[3]: airqualitylevel = 3 if iaq_index > AIRQUALITYLEVELLIMIT[ 3] and iaq_index <= AIRQUALITYLEVELLIMIT[4]: airqualitylevel = 4 if iaq_index > AIRQUALITYLEVELLIMIT[ 4] and iaq_index <= AIRQUALITYLEVELLIMIT[5]: airqualitylevel = 5 if iaq_index > AIRQUALITYLEVELLIMIT[5]: airqualitylevel = 6 airqualitytext = AIRQUALITYLEVELCONDITION[airqualitylevel] Devices[UNITALERTAIRQUALITY].Update(nValue=airqualitylevel, sValue=airqualitytext) Domoticz.Debug("Air Quality:" + str(airqualitylevel) + "," + airqualitytext) # Temperature ## nvalue=0 ## svalue=temperature/100 ## print("Temperature: " + str(temperature/100.0) + " °C") if temperature > 0: temperature = int(round(temperature / 100.0)) Devices[UNITTEMPERATURE].Update(nValue=0, sValue=str(temperature)) Domoticz.Debug(Devices[UNITTEMPERATURE].Name + "-Temperature:" + str(temperature)) # Humidity # nvalue=humidity # svalue=humiditystatus - 0=Normal,1=Comfortable,2=Dry,3=Wet # print("Humidity: " + str(humidity/100.0) + " %RH") if humidity > 0: humidity = int(round(humidity / 100.0)) humiditystatus = GetHumidityStatus(humidity) Devices[UNITHUMIDITY].Update(nValue=humidity, sValue=str(humiditystatus)) Domoticz.Debug(Devices[UNITHUMIDITY].Name + "-Humidity:" + str(humidity)) # Air Pressure # nvalue=0 # svalue=airpressure/100;prediction # print("Air Pressure: " + str(air_pressure/100.0) + " mbar") if air_pressure > 0: air_pressure = int(round(air_pressure / 100.0)) Devices[UNITBAROMETER].Update(nValue=0, sValue=str(air_pressure) + ";0") Domoticz.Debug(Devices[UNITBAROMETER].Name + "-Air Pressure:" + str(air_pressure)) Domoticz.Debug("Air Quality Devices updated") # AMBIENT LIGHT ## Get current illuminance ## nvalue=0 ## svalue=illuminance/100 illuminance = al.get_illuminance() if illuminance > 0: illuminance = int(round(illuminance / 100.0)) #print("Illuminance: " + str(illuminance/100.0) + " lx") Devices[UNITILLUMINATION].Update(nValue=0, sValue=str(illuminance)) Domoticz.Debug(Devices[UNITILLUMINATION].Name + "-Lux:" + str(illuminance)) # ## Tinkerforge Bricklet Updates # Domoticz.Debug("Tinkerforge updating...") ## LCD Display ## Writes text to a specific line (0 to 3) with a specific position (0 to 19). The text can have a maximum of 20 characters. ## Turn backlight on NOTE: done in onStart ## lcd.backlight_on() ## Domoticz.Debug("LCD Backlight ON") ## Clear the display lcd.clear_display() Domoticz.Debug("LCD Display cleared") ## Get the values as strings to write on the lcd ## AQI lcdaqi = str(iaq_index) ## TT:HH - TT=Temperature,HH=Humidity lcdtemperature = str(temperature) lcdhumidity = "HH" if humidity < 100: lcdhumidity = str(humidity) ## airpressure lcdairpressure = str(air_pressure) ## illuminance lcdilluminance = str(illuminance) ## write to the lcd: line (int,0-3),pos(int,0-19),text lcd.write_line(0, 0, "Q: " + lcdaqi + " ppm " + airqualitytext) lcd.write_line(1, 0, "T: " + lcdtemperature + " C") lcd.write_line(1, 14, "H: " + lcdhumidity + "%") lcd.write_line(2, 0, "P: " + lcdairpressure + " mbar") lcd.write_line(3, 0, "L: " + lcdilluminance + " lx") lcd.write_line(3, 14, PLUGINVERSION) Domoticz.Debug("LCD Lines written") ## rgb led set color depending indoor air quality index ## Set the brightness using the value of the parameter Mode2 lbbrightness = int(Parameters["Mode2"]) if lbbrightness < RGBBRIGHTNESSMIN: lbbrightness = RGBBRIGHTNESSMIN if lbbrightness > RGBBRIGHTNESSMAX: lbbrightness = RGBBRIGHTNESSMAX rl.set_rgb_value( SetRGBColor(AIRQUALITYLEVELCOLOR[airqualitylevel][0], lbbrightness), SetRGBColor(AIRQUALITYLEVELCOLOR[airqualitylevel][1], lbbrightness), SetRGBColor(AIRQUALITYLEVELCOLOR[airqualitylevel][2], lbbrightness)) Domoticz.Debug("RGB LED Color set") # Log Message Devices[UNITTEXTSTATUS].Update( nValue=0, sValue="OK: " + lcdaqi + "," + lcdtemperature + "," + lcdhumidity + "," + lcdairpressure) Domoticz.Log(Devices[UNITTEXTSTATUS].sValue) # Disconnect ipcon.disconnect() # Log Message Domoticz.Debug("Update OK.") except: # Error self.isError == 1 # Important to close the connection - if not, the plugin can not be disabled if self.ipConnected == 1: ipcon.disconnect() Devices[UNITTEXTSTATUS].Update( nValue=0, sValue= "[ERROR] Check settings, correct and restart Domoticz.") Domoticz.Log(Devices[UNITTEXTSTATUS].sValue)
if enumeration_type == IPConnection.ENUMERATION_TYPE_DISCONNECTED: print("") return print("Connected UID: " + connected_uid) print("Position: " + position) print("Hardware Version: " + str(hardware_version)) print("Firmware Version: " + str(firmware_version)) print("Device Identifier: " + str(device_identifier)) print("") if __name__ == "__main__": ipcon = IPConnection() # Create IP connection master = BrickMaster(UID_MASTER, ipcon) # Create device object ipcon.register_callback(IPConnection.CALLBACK_ENUMERATE, cb_enumerate) ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected ipcon.enumerate() time.sleep(0.5) rs485 = BrickletRS485(UID, ipcon) # Create device object master.set_spitfp_baudrate('c', 2000000) fw = open( '/home/olaf/tf/rs485-bricklet/software/build/rs485-bricklet-with-checksum.bin', 'rb').read()
voltage = str(master_2.get_stack_voltage()) # Verbrauch in ma current = str(master_2.get_stack_current()) out_str = 'Master_2\n{}\nSpannung:\t{}\tVerbrauch:\t{}'.format(info, voltage, current) print(out_str) if __name__ == "__main__": # Build dictionary from bricklet UIDS [relevant_sensors, relevant_uids] = build_dictionaries() # connect to daemon via ipconnection ipcon = IPConnection() uid_master_1 = '' uid_master_2 = '' master_1 = BrickMaster(uid_master_1, ipcon) master_2 = BrickMaster(uid_master_2, ipcon) ipcon.connect('localhost', 4223) # Stromverbrauch vor allen Sensoren print_verbrauch('Master alleine') # connect rest of sensors ipcon.disconnect() connected_sensors = Sensor.connect_sensors(relevant_sensors, relevant_uids, ipcon) ipcon.connect('localhost', 4223) # Stromverbrauch mit allen Sensoren print_verbrauch('Alle Sensoren') while True: # get sensor values sensor_values = {} for sensor in connected_sensors:
x1 = 2300.0 y1 = 2200.0 dist = (val - x0) * ((y1 - y0) / (x1 - x0)) return dist # Create a TCP/IP socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_address = (HOST_S, PORT_S) print >> sys.stderr, 'connecting to %s port %s' % server_address sock.connect(server_address) if __name__ == "__main__": ipcon = IPConnection() # Create IP connection master = BrickMaster(UID, ipcon) # Create device object a = BrickletAccelerometer(UIDa, ipcon) #dir = BrickletDistanceIR(UIDd, ipcon) dir = BrickletDistanceUS(UIDu, ipcon) ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Display master status and LED blink master.enable_status_led() print(master.get_identity()) cc = 0 # Get current stack voltage (unit is mV) try: while True: cc = cc + 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