Beispiel #1
0
def measure_bme280(ts_sensor):
    fields = {}
    try:
        temperature, pressure, humidity = readBME280All()

        # ThingSpeak fields
        # Create returned dict if ts-field is defined
        if 'ts_field_temperature' in ts_sensor and isinstance(
                temperature, (int, float)):
            fields[ts_sensor["ts_field_temperature"]] = round(temperature, 2)
        if 'ts_field_humidity' in ts_sensor and isinstance(
                humidity, (int, float)):
            fields[ts_sensor["ts_field_humidity"]] = round(humidity, 2)
        if 'ts_field_air_pressure' in ts_sensor and isinstance(
                pressure, (int, float)):
            fields[ts_sensor["ts_field_air_pressure"]] = round(pressure, 2)
    except OSError:
        print('No BME280 Sensor connected.')

    return fields
Beispiel #2
0
def measure_bme280(ts_sensor):
    fields = {}

    i2c_addr = 0x76 # default value
    offset = 0

    try:
        if 'i2c_addr' in ts_sensor:
            i2c_addr = ts_sensor["i2c_addr"]

            if i2c_addr == "0x76":
                i2c_addr = 0x76
            elif i2c_addr == "0x77":
                i2c_addr = 0x77
            else:
                logger.warning("Undefined BME280 I2C Address '" + str(i2c_addr) + "'")

    except Exception as ex:
        logger.error("Error getting I2C Adress, using default: '" + str(i2c_addr))

    try:
        temperature,pressure,humidity = readBME280All(i2c_addr)

        # ThingSpeak fields
        # Create returned dict if ts-field is defined
        if 'ts_field_temperature' in ts_sensor and isinstance(temperature, (int, float)):
            if 'offset' in ts_sensor and ts_sensor["offset"] is not None:
                offset = float(ts_sensor["offset"])
                temperature = temperature-offset
            fields[ts_sensor["ts_field_temperature"]] = round(temperature, 2)
        if 'ts_field_humidity' in ts_sensor and isinstance(humidity, (int, float)):
            fields[ts_sensor["ts_field_humidity"]] = round(humidity, 2)
        if 'ts_field_air_pressure' in ts_sensor and isinstance(pressure, (int, float)):
            fields[ts_sensor["ts_field_air_pressure"]] = round(pressure, 2)
    except OSError:
        logger.error("No BME280 Sensor connected on I2C Adress.")
    except Exception as ex:
        logger.exception("Unhandled Exception in measure_bme280")

    return fields
Beispiel #3
0
def bufferData():
    bmeVal = readBME280All()
    buffer("bme", {
        "time": dt.now(),
        "temp": bmeVal[0],
        "press": bmeVal[1],
        "hum": bmeVal[2]
    })

    mpuVal = getMpuData()
    buffer(
        "mpu", {
            "time": dt.now(),
            "gyro_x": mpuVal[0][0],
            "gyro_y": mpuVal[0][1],
            "gyro_z": mpuVal[0][2],
            "acc_x": mpuVal[1][0],
            "acc_y": mpuVal[1][1],
            "acc_z": mpuVal[1][2],
            "rot_x": mpuVal[2][0],
            "rot_y": mpuVal[2][1]
        })