BME280/BMP280

Github Repo C Header C source JS source
mongoose-os-libs/bme280 BME280.h   api_bme280.js

It uses Bosch Sensortec's reference implementation.

Both BMP280 and BME280 are supported with I2C or 4-wire SPI interface.

The library uses global instances of I2C or SPI with spi.cs0_gpio.

If different pins than the default ones are used, the user should define them in the config_schema of mos.yml


BME280

BME280(uint8_t addr, bool spi = false)
  : _bme(spi ? mgos_bme280_spi_create() : mgos_bme280_i2c_create(addr)) {
  }

Creates the BME280 object for the device with addr address

~BME280

~BME280() {
    mgos_bme280_delete(_bme);
  }

Deletes the object and frees resources.

read

int8_t read(struct mgos_bme280_data& data) {
    return mgos_bme280_read(_bme, &data);
  }

Reads the temperature, pressure and humidity in the provided data structure. If the device is BMP280, the humidity will be 0.

readTemperature

double readTemperature() {
    return mgos_bme280_read_temperature(_bme);
  }

Reads the temperature. Returns MGOS_BME280_ERROR if error.

readPressure

double readPressure() {
    return mgos_bme280_read_pressure(_bme);
  }

Reads the pressure. Returns MGOS_BME280_ERROR if error.

readHumidity

double readHumidity() {
    return mgos_bme280_read_humidity(_bme);
  }

Reads the humidity. If the device is BMP280, the humidity will be 0. Returns MGOS_BME280_ERROR if error.

isBME280

bool isBME280() {
    return mgos_bme280_is_bme280(_bme);
  }

Returns true if a BME280 device is connected

JS API


BME280Data.create

BME280Data.create()

Creates a BME280Data instance to be used for reading data from BME280. Return value: an object with the methods described below.

bmeData.free

bmeData.free()

Frees a BME280Data instance. No methods can be called on this instance after that. Return value: none.

bmeData.temp

bmeData.temp()

Gets the temperature component of the BME280Data structure.

bmeData.press

bmeData.press()

Gets the pressure component of the BME280Data structure.

bmeData.humid

bmeData.humid()

Gets the humidity component of the BME280Data structure.

BME280.createI2C

BME280.createI2C(address)

Creates a BME280 instance on the I2C bus with the given address address. Return value: an object with the methods described below.

BME280.createSPI

BME280.createSPI()

Creates a BME280 instance on the SPI bus, using spi.cs0_gpio Return value: an object with the methods described below.

bme.free

bme.free()

Frees the BME280 instance. No methods can be called on this instance after that. Return value: none.

bme.readAll

bme.readAll()

Reads all data into an instance of BME280Data Returns zero if success, otherwise a negative value.

bme.readTemp

bme.readTemp()

Return the temperature from the sensor in degrees C or BME280.MGOS_BME280_ERROR in case of a failure.

bme.readPress

bme.readPress()

Return the pressure from the sensor in Pa BME280.MGOS_BME280_ERROR in case of a failure.

bme.readHumid

bme.readHumid()

Return the humidity from the sensor in %RH BME280.MGOS_BME280_ERROR in case of a failure.

edit this doc