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 == LCD20x4.DEVICE_IDENTIFIER: try: self.lcd = LCD20x4(uid, self.ipcon) self.lcd.clear_display() self.lcd.backlight_on() log.info('LCD 20x4 initialized') except Error as e: log.error('LCD 20x4 init failed: ' + str(e.description)) self.lcd = None elif device_identifier == AmbientLight.DEVICE_IDENTIFIER: try: self.al = AmbientLight(uid, self.ipcon) self.al.set_illuminance_callback_period(5000) self.al.register_callback(self.al.CALLBACK_ILLUMINANCE, self.cb_illuminance) log.info('Ambient Light initialized') except Error as e: log.error('Ambient Light init failed: ' + str(e.description)) self.al = None elif device_identifier == AmbientLightV2.DEVICE_IDENTIFIER: try: self.al_v2 = AmbientLightV2(uid, self.ipcon) self.al_v2.set_configuration( AmbientLightV2.ILLUMINANCE_RANGE_64000LUX, AmbientLightV2.INTEGRATION_TIME_200MS) self.al_v2.set_illuminance_callback_period(5000) 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 = None elif device_identifier == Humidity.DEVICE_IDENTIFIER: try: self.hum = Humidity(uid, self.ipcon) self.hum.set_humidity_callback_period(5000) self.hum.register_callback(self.hum.CALLBACK_HUMIDITY, self.cb_humidity) log.info('Humidity initialized') except Error as e: log.error('Humidity init failed: ' + str(e.description)) self.hum = None elif device_identifier == Barometer.DEVICE_IDENTIFIER: try: self.baro = Barometer(uid, self.ipcon) self.baro.set_air_pressure_callback_period(5000) 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
def read_data(fake=None): """ Reads data from all weather sensors and returns it as Dictionary. In case of an error or outlier None is returned""" if fake: return weather_data try: ipcon = IPConnection() temp_bricklet = Temperature('qnk', ipcon) humidity_bricklet = Humidity('nLC', ipcon) barometer_bricklet = Barometer('k5g', ipcon) ipcon.connect(cfg['weather']['host'], int(cfg['weather']['port'])) temp_bricklet.set_i2c_mode(Temperature.I2C_MODE_SLOW) temp = temp_bricklet.get_temperature() / 100.0 if 45 < temp < -30: weather_data['temperature'] = None logger.warn( 'Got temperature value of %s Grade which is out of range' % temp) else: weather_data['temperature'] = temp humidity = humidity_bricklet.get_humidity() / 10.0 if humidity < 5: weather_data['humidity'] = None logger.warn('Got humidity value of %s RH which is out of range' % humidity) else: weather_data['humidity'] = humidity pressure = barometer_bricklet.get_air_pressure() / 1000.0 if 1080 < pressure < 930: weather_data['pressure'] = None logger.warn('Got pressure value of %s mbar which is out of range' % pressure) else: weather_data['pressure'] = pressure ipcon.disconnect() return weather_data except Exception as e: logger.error('Cloud not connect to weather sensors: %s' % str(e)) return
def __init__(self, parent=None): QMainWindow.__init__(self, parent) self.initialized = False self.altitude_error_i = 0 self.acc_scale = 0.0 self.start_time = time.time() self.altitude_error = 0 self.inst_acceleration = 0.0 self.delta = 0 self.estimated_velocity = 0.0 self.estimated_altitude = 0.0 self.last_time = time.time() self.last_orig_altitude = 0 self.last_estimated_altitude = 0 ipcon = IPConnection() self.imu = IMU(UID_IMU, ipcon) self.barometer = Barometer(UID_BAROMETER, ipcon) ipcon.connect(HOST, PORT) # Turn leds and orientation calculation off, to save calculation time # for the IMU Brick. This makes sure that the measurements are taken # in equidistant 2ms intervals self.imu.leds_off() self.imu.orientation_calculation_off() # Turn averaging of in the Barometer Bricklet to make sure that # the data is without delay self.barometer.set_averaging(0, 0, 0) red_pen = QPen(Qt.red) red_pen.setWidth(5) plot_list = [ #['', Qt.blue, self.get_orig_value], ['', red_pen, self.get_estimated_value] ] self.plot_widget = PlotWidget('Height [m]', plot_list) self.plot_widget.stop = False self.setCentralWidget(self.plot_widget) self.timer = QTimer() self.timer.timeout.connect(self.update) self.timer.start(6)
def __init__(self, uid, connection, logging_daemon, queue, value=0.0, trigger_difference=0.5): self.bricklet = Barometer(uid, connection) self._value = value self._value_old = value self.trigger_difference = trigger_difference self._rising = False self._falling = False self.uid = uid self._logging_daemon = logging_daemon self._queue = queue self._logging_daemon.info( 'Tinkerforge ... Barometer-Bricklet UID "%s" initialisiert' % uid)