From 77c20e1bda05b843a9e37338d88e2065275f46e7 Mon Sep 17 00:00:00 2001 From: mschader Date: Wed, 4 Oct 2017 00:41:21 +0200 Subject: [PATCH 1/2] Add support for BME280 environmental sensors --- framework/features/BME280.h | 55 +++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 framework/features/BME280.h diff --git a/framework/features/BME280.h b/framework/features/BME280.h new file mode 100644 index 0000000..cd254c0 --- /dev/null +++ b/framework/features/BME280.h @@ -0,0 +1,55 @@ +#ifndef BME280_SENSOR_H +#define BME280_SENSOR_H + +#include "Feature.h" +#include + +#define SEALEVELPRESSURE_HPA (1013.25) + +template +class BME280 : public Feature { + +protected: + using Feature::LOG; + Adafruit_BME280 bme280; + +public: + + BME280(Device* device) : + Feature(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 From 857d5095469c31ce4ae66e8920834821906e7c99 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Tue, 6 Mar 2018 20:39:19 +0100 Subject: [PATCH 2/2] Add BME280 example device --- devices/example-bme280/Impl.cpp | 25 +++++++++++++++++++++++++ devices/example-bme280/Readme.md | 6 ++++++ 2 files changed, 31 insertions(+) create mode 100644 devices/example-bme280/Impl.cpp create mode 100644 devices/example-bme280/Readme.md diff --git a/devices/example-bme280/Impl.cpp b/devices/example-bme280/Impl.cpp new file mode 100644 index 0000000..00b8b43 --- /dev/null +++ b/devices/example-bme280/Impl.cpp @@ -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; +}; + + +Device* createDevice() { + return new Bme280Device(); +} + + diff --git a/devices/example-bme280/Readme.md b/devices/example-bme280/Readme.md new file mode 100644 index 0000000..537210f --- /dev/null +++ b/devices/example-bme280/Readme.md @@ -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