diff --git a/firmware/config.h b/firmware/config.h index 7459542..811da32 100644 --- a/firmware/config.h +++ b/firmware/config.h @@ -4,6 +4,7 @@ #define SENSOR_HUMIDITY 1 #define SENSOR_LIGHT 2 #define SENSOR_WINDSPEED 3 +#define SENSOR_PRESSURE 4 #define UPDATE_INTERVAL 4 diff --git a/firmware/firmware.ino b/firmware/firmware.ino index 543502c..ff439f2 100644 --- a/firmware/firmware.ino +++ b/firmware/firmware.ino @@ -4,6 +4,9 @@ #include #include #include +#include // Adafruit Unified Sensor +#include // https://github.com/adafruit/Adafruit_APDS9960 +#include // https://github.com/adafruit/Adafruit_BME280_Library #include "config.h" @@ -28,6 +31,8 @@ float currentSensorData[4] = {0.0, 0.0, 0.0, 0.0}; WiFiManager wifiManager; Influxdb influxdb(INFLUXDB_HOST, INFLUXDB_PORT); +Adafruit_APDS9960 apds; +Adafruit_BME280 bme; void setup() { #ifdef DEBUG @@ -55,6 +60,13 @@ void setup() { // Open the InfluxDB session influxdb.opendb(INFLUXDB_DB, INFLUXDB_USER, INFLUXDB_PASS); delay(2000); + + // Initialize and configure the sensors + apds.begin(); + apds.enableColor(true); + bme.begin(); + + delay(100); } void loop() { @@ -64,6 +76,7 @@ void loop() { currentSensorData[SENSOR_HUMIDITY] = fetchHumidity(); currentSensorData[SENSOR_LIGHT] = fetchLight(); currentSensorData[SENSOR_WINDSPEED] = fetchWindspeed(); + currentSensorData[SENSOR_PRESSURE] = fetchPressure(); #ifdef DEBUG Serial.println(""); @@ -72,6 +85,7 @@ void loop() { Serial.println("Humidity: " + String(currentSensorData[SENSOR_HUMIDITY]) + "%"); Serial.println("Light: " + String(currentSensorData[SENSOR_LIGHT]) + " Lumen"); Serial.println("Windspeed: " + String(currentSensorData[SENSOR_WINDSPEED]) + " Km/h"); + Serial.println("Pressure: " + String(currentSensorData[SENSOR_PRESSURE]) + " hPa"); #endif pushToInfluxDB(DEVICE_NAME, currentSensorData); diff --git a/firmware/influxdb.ino b/firmware/influxdb.ino index 4fdee39..2756d63 100644 --- a/firmware/influxdb.ino +++ b/firmware/influxdb.ino @@ -3,4 +3,5 @@ void pushToInfluxDB(String device, float sensorValues[]) { influxdb.write("weather,device=" + device + " humidity=" + String(sensorValues[SENSOR_HUMIDITY])); influxdb.write("weather,device=" + device + " light=" + String(sensorValues[SENSOR_LIGHT])); influxdb.write("weather,device=" + device + " windspeed=" + String(sensorValues[SENSOR_WINDSPEED])); + influxdb.write("weather,device=" + device + " pressure=" + String(sensorValues[SENSOR_PRESSURE])); } diff --git a/firmware/sensors.ino b/firmware/sensors.ino index 5538e12..3d5e93b 100644 --- a/firmware/sensors.ino +++ b/firmware/sensors.ino @@ -2,15 +2,26 @@ int anemometerRotations = 0; unsigned long currentTime = 0; float fetchTemperature() { - return 22.5; // XXX: Dummy value + return bme.readTemperature(); +} + +float fetchPressure() { + return bme.readPressure() / 100.0F; } float fetchHumidity() { - return 60.0; // XXX: Dummy value + return bme.readHumidity(); } float fetchLight() { - return 2000.4; // XXX: Dummy value + uint16_t red, green, blue, white; + + while(!apds.colorDataReady()){ + delay(5); + } + + apds.getColorData(&red, &green, &blue, &white); + return white; } void anemometerInterrupt() {