Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Add support for the Bosch BME280 environmental sensor #31

Merged
merged 2 commits into from
Mar 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions devices/example-bme280/Impl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "../features/BME280.h"
#include "Device.h"


constexpr const char BME280_NAME[] = "bme280";
const uint8_t BME280_I2C_ADDR = 0x76;

class Bme280Device : public Device {
public:
Bme280Device() :
bme280(this)
{
this->add(&(this->bme280));
}

private:
BME280<BME280_NAME, BME280_I2C_ADDR> bme280;
};


Device* createDevice() {
return new Bme280Device();
}


6 changes: 6 additions & 0 deletions devices/example-bme280/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
An example device featuring the [Bosch BME280](https://www.bosch-sensortec.com/bst/products/all_products/bme280) environmental sensor.

It provides data on:
- barometric pressure
- relative humidity
- temperature
55 changes: 55 additions & 0 deletions framework/features/BME280.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#ifndef BME280_SENSOR_H
#define BME280_SENSOR_H

#include "Feature.h"
#include <Libraries/Adafruit_BME280_Library/Adafruit_BME280.h>

#define SEALEVELPRESSURE_HPA (1013.25)

template<const char* const name, uint8_t addr>
class BME280 : public Feature<name> {

protected:
using Feature<name>::LOG;
Adafruit_BME280 bme280;

public:

BME280(Device* device) :
Feature<name>(device) {

bool status;
status = bme280.begin(addr);
if (!status) {
Serial.println("Could not detect a BME280 sensor, check wiring!");
while (1);
}

delay(100); // wait for the sensor to boot up

this->updateTimer.initializeMs(15000, TimerDelegate(&BME280::publishCurrentState, this));
this->updateTimer.start(true);
}

protected:
virtual void publishCurrentState() {
long pressure = bme280.readPressure();
LOG.log("Pressure:", pressure);
this->publish("pressure", String(pressure));

float temperature = bme280.readTemperature();
LOG.log("Temperature:", temperature);
this->publish("temperature", String(temperature));

float humidity = bme280.readHumidity();
LOG.log("Humidity", humidity);
this->publish("humidity", String(humidity));
}

private:
Timer updateTimer;

};


#endif